﻿namespace WMS6.BLL
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class OutboundMgtBLL
    {
        private static readonly IAdjustmentDA adjustmentDA = DataAccess.CreateAdjustmentDA();
        private static readonly IAdjustmentDetailDA adjustmentDetailDA = DataAccess.CreateAdjustmentDetailDA();
        private static readonly IAllocateRuleDetailDA allocateRuleDetailDA = DataAccess.CreateAllocateRuleDetailDA();
        private static readonly IBomDA bomDA = DataAccess.CreateBomDA();
        private static readonly IBomDetailDA bomDetailDA = DataAccess.CreateBomDetailDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private string CurrentWH;
        private List<string> dataBaseID;
        private static readonly IDbConfigDA dbConfigDA = DataAccess.CreateDbConfigDA();
        private static readonly IDistributionRangeDA iDistributionRangeDA = DataAccess.CreateDistributionRangeDA();
        private static readonly IIntransitDA inTransitDA = DataAccess.CreateIntransitDA();
        private static readonly IIntransitDetailDA inTransitDetailDA = DataAccess.CreateIntransitDetailDA();
        private static readonly IInventoryMgtDA inventoryMgtDA = DataAccess.CreateInventoryMgtDA();
        private static readonly IInvLotDA invLotDA = DataAccess.CreateInvLotDA();
        private static readonly IInvLotLocLpnDA invLotLocLpnDA = DataAccess.CreateInvLotLocLpnDA();
        private static readonly IInvSkuLocDA invSkuLocDA = DataAccess.CreateInvSkuLocDA();
        private static readonly IInvTransDA invTransDA = DataAccess.CreateInvTransDA();
        private static readonly ILoadDetailDA loadDetailDA = DataAccess.CreateLoadDetailDA();
        private static readonly ILocationDA locationDA = DataAccess.CreateLocationDA();
        private static readonly ILotAttributeDA lotAttributeDA = DataAccess.CreateLotAttributeDA();
        private static readonly ILpnDA lpnDA = DataAccess.CreateLpnDA();
        private static readonly IOrderDetailDA orderDetailDA = DataAccess.CreateOrderDetailDA();
        private static readonly IOrdersDA ordersDA = DataAccess.CreateOrdersDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private static readonly IPickDetailDA pickDetailDa = DataAccess.CreatePickDetailDA();
        private static readonly IPreallocatePickDetailDA preAllocatePickDetailDA = DataAccess.CreatePreallocatePickDetailDA();
        private static readonly IPreallocateRuleDA preAllocateRuleDA = DataAccess.CreatePreallocateRuleDA();
        private static readonly IPreallocateRuleDetailDA preAllocateRuleDetailDA = DataAccess.CreatePreallocateRuleDetailDA();
        private PubParasInfo pubParasInfo;
        private static readonly IReceiptDA receiptDA = DataAccess.CreateReceiptDA();
        private static readonly IPhysicalRequestDA RequestDA = DataAccess.CreatePhysicalRequestDA();
        private static readonly IRotationRuleDA rotataionRuleDA = DataAccess.CreateRotationRuleDA();
        private static readonly IRotationRuleDetailDA rotataionRuleDetailDA = DataAccess.CreateRotationRuleDetailDA();
        private static readonly ISalesOrderDA salesOrderDA = DataAccess.CreateSalesOrderDA();
        private static readonly ISalesOrderDetailDA salesOrderDetailDA = DataAccess.CreateSalesOrderDetailDA();
        private static readonly IShipmentContainerDA shipmentContainerDA = DataAccess.CreateShipmentContainerDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly ISubstituteSkuDA substituteSkuDA = DataAccess.CreateSubstituteSkuDA();
        private static readonly ISysSettingDA sysSettingDA = DataAccess.CreateSysSettingDA();
        private static readonly IPhysicalTagDA TagDA = DataAccess.CreatePhysicalTagDA();
        private static readonly ITaskDetailDA taskDetailDa = DataAccess.CreateTaskDetailDA();
        private static readonly IWaveDetailDA waveDetailDA = DataAccess.CreateWaveDetailDA();
        private static readonly IZoneDA zoneDA = DataAccess.CreateZoneDA();

        public OutboundMgtBLL()
        {
            this.pubParasInfo = null;
        }

        public OutboundMgtBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.CurrentWH = currentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public OutboundMgtBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.CurrentWH = tempPubParasInfo.CurrentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        private List<InvLotLocLpnInfo> AddInvLotLocLpn2List(List<InvLotLocLpnInfo> invloclotlpns, DataTable dt)
        {
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                InvLotLocLpnInfo invlotloclpn = null;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    invlotloclpn = new InvLotLocLpnInfo(int.Parse(dt.Rows[i]["ROWID"].ToString()), dt.Rows[i]["WH_ID"].ToString(), dt.Rows[i]["LOT"].ToString(), dt.Rows[i]["LOC"].ToString(), dt.Rows[i]["LPN_ID"].ToString(), dt.Rows[i]["OWNER_ID"].ToString(), dt.Rows[i]["SKU_ID"].ToString(), decimal.Parse(dt.Rows[i]["QTY"].ToString()), decimal.Parse(dt.Rows[i]["ALLOCATED_QTY"].ToString()), decimal.Parse(dt.Rows[i]["PICKED_QTY"].ToString()), decimal.Parse(dt.Rows[i]["EXPECTED_QTY"].ToString()), decimal.Parse(dt.Rows[i]["PICKINPROCESS_QTY"].ToString()), decimal.Parse(dt.Rows[i]["PENDING_MOVE_IN"].ToString()), decimal.Parse(dt.Rows[i]["ARCHIVE_QTY"].ToString()), DateTime.Parse(dt.Rows[i]["ARCHIVE_DATE"].ToString()), dt.Rows[i]["HOLD_STATUS"].ToString(), (byte[]) dt.Rows[i]["TS"], dt.Rows[i]["CREATED_BY"].ToString(), DateTime.Parse(dt.Rows[i]["CREATED_DATE"].ToString()), dt.Rows[i]["UPDATED_BY"].ToString(), DateTime.Parse(dt.Rows[i]["UPDATED_DATE"].ToString()), decimal.Parse(dt.Rows[i]["AVAILABLE_QTY"].ToString()));
                    invloclotlpns.Add(invlotloclpn);
                }
            }
            return invloclotlpns;
        }

        private string AllocatedByPreallocatePickDetailInfo(PreallocatePickDetailInfo preallocatePickDetailInfo, AllocateRuleDetailInfo allocateRuleDetailInfo, OrderDetailInfo orderDetailInfo, PackInfo packInfo, ref decimal totalAllocatedQty, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                DataSet ds = orderDetailDA.GetInvQty4AllocateByStrategy(dataBase, tran, allocateRuleDetailInfo.AllocateStrategy, preallocatePickDetailInfo.Lot, (preallocatePickDetailInfo.Qty / preallocatePickDetailInfo.UomQty).ToString(), preallocatePickDetailInfo.OwnerID, preallocatePickDetailInfo.SkuID, whLoginID);
                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    decimal factor = Convert.ToDecimal(this.ExchangeAllocateStratetyUom2PackFactor(packInfo, allocateRuleDetailInfo.UomID));
                    decimal remainQty = preallocatePickDetailInfo.Qty;
                    if (factor != 0M)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            decimal availablePackQty = decimal.Parse(ds.Tables[0].Rows[i]["QTYAVAILABLE"].ToString()) / factor;
                            if (availablePackQty > 0M)
                            {
                                PickDetailInfo pickDetailInfo;
                                decimal deductAllocateQty = 0M;
                                if (availablePackQty >= Convert.ToDecimal((decimal) (remainQty / factor)))
                                {
                                    deductAllocateQty = remainQty;
                                    preallocatePickDetailInfo.Qty -= deductAllocateQty;
                                    remainQty -= deductAllocateQty;
                                    orderDetailInfo.PreallocatedQty -= deductAllocateQty;
                                    orderDetailInfo.AllocatedQty += deductAllocateQty;
                                    totalAllocatedQty += deductAllocateQty;
                                }
                                else
                                {
                                    deductAllocateQty = availablePackQty * factor;
                                    preallocatePickDetailInfo.Qty -= deductAllocateQty;
                                    remainQty -= deductAllocateQty;
                                    orderDetailInfo.PreallocatedQty -= deductAllocateQty;
                                    orderDetailInfo.AllocatedQty += deductAllocateQty;
                                    totalAllocatedQty += deductAllocateQty;
                                }
                                pickDetailInfo = new PickDetailInfo();
                                pickDetailInfo.PickDetailID = commonMethod.GenNextNumStr(dataBase, tran, "PICK_DETAIL", whLoginID);
                                pickDetailInfo.Lot = preallocatePickDetailInfo.Lot;
                                pickDetailInfo.Loc = ds.Tables[0].Rows[i]["LOC"].ToString();
                                pickDetailInfo.LpnID = ds.Tables[0].Rows[i]["LPN_ID"].ToString();
                                pickDetailInfo.ToLoc = this.GetDetailPickToLocByFromLoc(dataBase, tran, pickDetailInfo.Loc, whLoginID);
                                pickDetailInfo.OrderID = preallocatePickDetailInfo.OrderID;
                                pickDetailInfo.OrderLineID = preallocatePickDetailInfo.OrderLineID;
                                pickDetailInfo.PreallocatePickDetailID = preallocatePickDetailInfo.PreallocatePickDetailID;
                                pickDetailInfo.OwnerID = preallocatePickDetailInfo.OwnerID;
                                pickDetailInfo.PackID = preallocatePickDetailInfo.PackID;
                                pickDetailInfo.Qty = deductAllocateQty;
                                pickDetailInfo.SkuID = preallocatePickDetailInfo.SkuID;
                                pickDetailInfo.Status = PickDetailStatus.New;
                                pickDetailInfo.UomID = this.ExchangeAllocateStratetyUom2PackUom(packInfo, allocateRuleDetailInfo.UomID);
                                pickDetailInfo.CaseID = "";
                                pickDetailInfo.AltSkuID = "";
                                pickDetailInfo.DropID = "";
                                pickDetailInfo.UomQty = preallocatePickDetailInfo.UomQty;
                                pickDetailInfo.MovedQty = 0M;
                                pickDetailInfo.UpdateSource = "";
                                pickDetailInfo.PickMethod = "";
                                pickDetailInfo.WaveID = "";
                                pickDetailInfo.FreightCharges = 0.0;
                                pickDetailInfo.IsClosed = "";
                                pickDetailInfo.QcStatus = "";
                                pickDetailInfo.EffectiveDate = DateTime.Now;
                                pickDetailInfo.CreatedBy = updatedBy;
                                pickDetailInfo.UpdatedBy = updatedBy;
                                temp = temp + pickDetailDa.InsertPickDetail(dataBase, tran, pickDetailInfo, whLoginID);
                                decimal tempPreallocateQty = deductAllocateQty * -1M;
                                preAllocatePickDetailDA.UpdatePreAllocatePickDetailQty(dataBase, tran, preallocatePickDetailInfo.PreallocatePickDetailID, tempPreallocateQty, updatedBy, whLoginID);
                                InvLotInfo invLotinfo = new InvLotInfo {
                                    Lot = preallocatePickDetailInfo.Lot,
                                    UpdatedBy = updatedBy,
                                    AllocatedQty = deductAllocateQty,
                                    AllocatedGrossWgt = 0.0,
                                    AllocatedNetWgt = 0.0
                                };
                                invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.AllocatedQtyWgt, whLoginID);
                                InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                    Lot = preallocatePickDetailInfo.Lot,
                                    Loc = ds.Tables[0].Rows[i]["LOC"].ToString(),
                                    LpnID = ds.Tables[0].Rows[i]["LPN_ID"].ToString(),
                                    AllocatedQty = deductAllocateQty,
                                    UpdatedBy = updatedBy
                                };
                                invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.AllocatedQty, whLoginID);
                                InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                                    Loc = ds.Tables[0].Rows[i]["LOC"].ToString(),
                                    SkuID = preallocatePickDetailInfo.SkuID,
                                    OwnerID = preallocatePickDetailInfo.OwnerID,
                                    UpdatedBy = updatedBy,
                                    AllocatedQty = deductAllocateQty
                                };
                                invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.AllocatedQty, whLoginID);
                            }
                            if (remainQty == 0M)
                            {
                                break;
                            }
                        }
                    }
                    tran.Commit();
                }
                return temp;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string AutoAllocate(string orderID, string updatedBy)
        {
            this.AutoPreAllocate(orderID, updatedBy);
            string successMsg = string.Empty;
            string failMsg = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = " AND OD.STATUS IN ('NEW','PARTPRE-ALLOCATED','PRE-ALLOCATED') ";
            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                Dictionary<string, List<AllocateRuleDetailInfo>> allocateRuleDetailInfoDic = new Dictionary<string, List<AllocateRuleDetailInfo>>();
                Dictionary<string, PackInfo> packInfoDic = new Dictionary<string, PackInfo>();
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    List<AllocateRuleDetailInfo> allocateRuleDetailInfos = null;
                    if (allocateRuleDetailInfoDic.ContainsKey(orderDetailInfo.AllocateRuleID))
                    {
                        allocateRuleDetailInfoDic.TryGetValue(orderDetailInfo.AllocateRuleID, out allocateRuleDetailInfos);
                    }
                    else
                    {
                        allocateRuleDetailInfos = allocateRuleDetailDA.GetAllocateRuleDetailListByID(orderDetailInfo.AllocateRuleID, whLoginID, this.pubParasInfo);
                        allocateRuleDetailInfoDic.Add(orderDetailInfo.AllocateRuleID, allocateRuleDetailInfos);
                    }
                    PackInfo packInfo = null;
                    if (packInfoDic.ContainsKey(orderDetailInfo.PackID))
                    {
                        packInfoDic.TryGetValue(orderDetailInfo.PackID, out packInfo);
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                        packInfoDic.Add(orderDetailInfo.PackID, packInfo);
                    }
                    if ((allocateRuleDetailInfos != null) && (allocateRuleDetailInfos.Count > 0))
                    {
                        decimal totalAllocatedQty = 0M;
                        int failCount = 0;
                        int strategyFailCounter = 0;
                        foreach (AllocateRuleDetailInfo allocateRuleDetailInfo in allocateRuleDetailInfos)
                        {
                            if (allocateRuleDetailInfo.IsActive == "Y")
                            {
                                List<PreallocatePickDetailInfo> preallocatePickDetailInfos = preAllocatePickDetailDA.GetPreallocatePickDetailListByAllocateUomID(orderID, orderDetailInfo.LineID, allocateRuleDetailInfo.UomID, whLoginID);
                                if ((preallocatePickDetailInfos != null) && (preallocatePickDetailInfos.Count > 0))
                                {
                                    string temp2 = string.Empty;
                                    foreach (PreallocatePickDetailInfo preallocatePickDetailInfo in preallocatePickDetailInfos)
                                    {
                                        temp2 = this.AllocatedByPreallocatePickDetailInfo(preallocatePickDetailInfo, allocateRuleDetailInfo, orderDetailInfo, packInfo, ref totalAllocatedQty, updatedBy, whLoginID);
                                    }
                                    if (string.IsNullOrEmpty(temp2))
                                    {
                                        failCount++;
                                    }
                                }
                                else
                                {
                                    strategyFailCounter++;
                                }
                            }
                        }
                        if ((failCount == allocateRuleDetailInfos.Count) && ((failCount > 0) && (failCount <= allocateRuleDetailInfos.Count)))
                        {
                            failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_024", this.pubParasInfo.UserLanguage);
                        }
                        else if (strategyFailCounter == allocateRuleDetailInfos.Count)
                        {
                            failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_023", this.pubParasInfo.UserLanguage);
                        }
                        else
                        {
                            successMsg = successMsg + orderDetailInfo.LineID.ToString() + ",";
                        }
                        string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                        orderDetailDA.UpdateOrderDetailStatusAndQty(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, totalAllocatedQty, updatedBy, OrderDetailUpdateType.AllocatedQty, whLoginID);
                        this.UpdateSalesOrderDetailStatusAndQty(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), OrderStatus.Allocated, 0M, whLoginID, this.pubParasInfo);
                    }
                    else
                    {
                        failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_022", this.pubParasInfo.UserLanguage);
                    }
                }
                string orderStatus = orderBll.GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, updatedBy, whLoginID);
                new WaveBLL(this.pubParasInfo).UpdateWaveStatusByOrderID(orderID);
            }
            successMsg = string.IsNullOrEmpty(successMsg) ? "" : (PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + successMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_021", this.pubParasInfo.UserLanguage));
            failMsg = string.IsNullOrEmpty(failMsg) ? "" : (" //" + failMsg);
            return (successMsg + failMsg);
        }

        private bool AutomaticExecuteExploaing(DataBase dataBase, DbTransaction tran, OrderDetailInfo orderDetailInfo, List<string> SkuName)
        {
            string whLoginID = this.dataBaseID[0];
            decimal dQty = orderDetailInfo.OriginalQty;
            BomInfo bomInfo = bomDA.GetBomByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
            SkuName.Add(orderDetailInfo.SkuID);
            if (bomInfo != null)
            {
                bomInfo.BomDetailInfo = bomDetailDA.GetBomDetailListByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                if (bomInfo.BomDetailInfo.Count <= 0)
                {
                    return true;
                }
                orderDetailDA.DeleteOrderDetail(dataBase, tran, new List<string> { orderDetailInfo.OrderID }, new List<string> { orderDetailInfo.LineID.ToString() }, this.dataBaseID);
                foreach (BomDetailInfo info in bomInfo.BomDetailInfo)
                {
                    for (int i = 0; SkuName.Count > i; i++)
                    {
                        if (info.ComponentSkuID == SkuName[i])
                        {
                            return false;
                        }
                    }
                    SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, info.OwnerID, info.SkuID, whLoginID);
                    if (skuInfo != null)
                    {
                        PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuInfo.PackID, whLoginID);
                        orderDetailInfo.LineID += 10;
                        orderDetailInfo.SkuID = info.ComponentSkuID;
                        orderDetailInfo.OriginalQty = dQty * info.Qty;
                        orderDetailInfo.PackID = skuInfo.PackID;
                        orderDetailInfo.UomID = packInfo.PackUom1;
                        orderDetailDA.InsertOrderDetail(dataBase, tran, orderDetailInfo, whLoginID);
                        if (!this.AutomaticExecuteExploaing(dataBase, tran, orderDetailInfo, SkuName))
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        public string AutoPreAllocate(string orderID, string updatedBy)
        {
            string successMsg = string.Empty;
            string failMsg = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = " AND OD.STATUS IN ('NEW','PARTPRE-ALLOCATED','PRE-ALLOCATED') ";
            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                Dictionary<string, PreallocateRuleInfo> preallocateRuleInfoDic = new Dictionary<string, PreallocateRuleInfo>();
                Dictionary<string, PackInfo> packInfoDic = new Dictionary<string, PackInfo>();
                Dictionary<string, SkuInfo> skuInfoDic = new Dictionary<string, SkuInfo>();
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    string CS00003;
                    if (!string.IsNullOrEmpty(orderDetailInfo.PreallocateRuleID))
                    {
                        PreallocateRuleInfo preAllocateRuleInfo = null;
                        if (preallocateRuleInfoDic.ContainsKey(orderDetailInfo.PreallocateRuleID))
                        {
                            preallocateRuleInfoDic.TryGetValue(orderDetailInfo.PreallocateRuleID, out preAllocateRuleInfo);
                        }
                        else
                        {
                            preAllocateRuleInfo = preAllocateRuleDA.GetPreallocateRuleByID(orderDetailInfo.PreallocateRuleID, whLoginID);
                            if (preAllocateRuleInfo != null)
                            {
                                preAllocateRuleInfo.PreallocateRuleDetailInfos = preAllocateRuleDetailDA.GetPreallocateRuleDetailListByID(preAllocateRuleInfo.PreallocateRuleID, whLoginID, this.pubParasInfo);
                                preallocateRuleInfoDic.Add(orderDetailInfo.PreallocateRuleID, preAllocateRuleInfo);
                            }
                            else
                            {
                                CS00003 = failMsg;
                                failMsg = CS00003 + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_015", this.pubParasInfo.UserLanguage) + ",";
                                continue;
                            }
                        }
                        PackInfo packInfo = null;
                        if (packInfoDic.ContainsKey(orderDetailInfo.PackID))
                        {
                            packInfoDic.TryGetValue(orderDetailInfo.PackID, out packInfo);
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                            packInfoDic.Add(orderDetailInfo.PackID, packInfo);
                        }
                        SkuInfo skuInfo = null;
                        if (skuInfoDic.ContainsKey(orderDetailInfo.OwnerID + orderDetailInfo.SkuID))
                        {
                            skuInfoDic.TryGetValue(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, out skuInfo);
                        }
                        else
                        {
                            skuInfo = skuDA.GetSkuByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                            skuInfoDic.Add(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, skuInfo);
                        }
                        bool successFlag = false;
                        string temp2 = this.PreallocatedByOrderDetail(orderDetailInfo, orderDetailBLL, preAllocateRuleInfo, packInfo, skuInfo, updatedBy, whLoginID, ref successFlag);
                        if (successFlag)
                        {
                            successMsg = successMsg + orderDetailInfo.LineID.ToString() + ",";
                        }
                        else
                        {
                            failMsg = failMsg + temp2 + ",";
                        }
                    }
                    else
                    {
                        CS00003 = failMsg;
                        failMsg = CS00003 + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_016", this.pubParasInfo.UserLanguage) + ",";
                        continue;
                    }
                }
                string orderStatus = new OrdersBLL(this.pubParasInfo).GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, updatedBy, whLoginID);
                new WaveBLL(this.pubParasInfo).UpdateWaveStatusByOrderID(orderID);
            }
            failMsg = string.IsNullOrEmpty(failMsg) ? "" : (" //" + failMsg);
            successMsg = string.IsNullOrEmpty(successMsg) ? "" : (PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + successMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_012", this.pubParasInfo.UserLanguage));
            return (successMsg + failMsg);
        }

        public string AutoRevertAllocate(string orderID, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            try
            {
                string where = " AND PD.STATUS = 'New' ";
                List<PickDetailInfo> pickDetailInfos = pickDetailDa.GetPickDetailByOrderID(orderID, where, whLoginID, this.pubParasInfo);
                temp = this.RevertAllocate(pickDetailInfos, updatedBy);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string AutoRevertPreAllocate(string orderID, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            try
            {
                string where = " AND OD.STATUS <> 'Shipped' ";
                List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
                if ((orderDetailInfos == null) || (orderDetailInfos.Count <= 0))
                {
                    return temp;
                }
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    if (orderDetailInfo.PreallocatedQty > 0M)
                    {
                        DataBase dataBase = new DataBase();
                        DbConnection conn = dataBase.connection;
                        conn.Open();
                        DbTransaction tran = conn.BeginTransaction();
                        try
                        {
                            decimal revertPreAllocateQty = this.RevertOrderDetailPreAllocate(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), whLoginID);
                            orderDetailInfo.PreallocatedQty -= revertPreAllocateQty;
                            string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                            orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, revertPreAllocateQty * -1M, updatedBy, OrderDetailUpdateType.Status, whLoginID);
                            this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                            temp = temp + orderDetailInfo.LineID.ToString() + ",";
                            tran.Commit();
                        }
                        catch
                        {
                            tran.Rollback();
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
                string orderStatus = new OrdersBLL().GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string BatchAllocate(string orderID, List<string> orderLineIDS, string updatedBy)
        {
            string successMsg = string.Empty;
            string failMsg = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = " AND OD.STATUS IN ('NEW','PARTPRE-ALLOCATED','PRE-ALLOCATED') AND OD.LINE_ID IN ('";
            if ((orderLineIDS != null) && (orderLineIDS.Count > 0))
            {
                for (int i = 0; i < orderLineIDS.Count; i++)
                {
                    where = where + orderLineIDS[i] + "','";
                }
                where = where.Substring(0, where.Length - 2) + ")";
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("F7100_010", this.pubParasInfo.UserLanguage);
            }
            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                Dictionary<string, PreallocateRuleInfo> preallocateRuleInfoDic = new Dictionary<string, PreallocateRuleInfo>();
                Dictionary<string, PackInfo> packInfoDic = new Dictionary<string, PackInfo>();
                Dictionary<string, SkuInfo> skuInfoDic = new Dictionary<string, SkuInfo>();
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    PreallocateRuleInfo preAllocateRuleInfo = null;
                    if (preallocateRuleInfoDic.ContainsKey(orderDetailInfo.PreallocateRuleID))
                    {
                        preallocateRuleInfoDic.TryGetValue(orderDetailInfo.PreallocateRuleID, out preAllocateRuleInfo);
                    }
                    else
                    {
                        preAllocateRuleInfo = preAllocateRuleDA.GetPreallocateRuleByID(orderDetailInfo.PreallocateRuleID, whLoginID);
                        if (preAllocateRuleInfo != null)
                        {
                            preAllocateRuleInfo.PreallocateRuleDetailInfos = preAllocateRuleDetailDA.GetPreallocateRuleDetailListByID(preAllocateRuleInfo.PreallocateRuleID, whLoginID, this.pubParasInfo);
                            preallocateRuleInfoDic.Add(orderDetailInfo.PreallocateRuleID, preAllocateRuleInfo);
                        }
                        else
                        {
                            string CS00003 = failMsg;
                            failMsg = CS00003 + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_015", this.pubParasInfo.UserLanguage) + ",";
                            continue;
                        }
                    }
                    PackInfo packInfo = null;
                    if (packInfoDic.ContainsKey(orderDetailInfo.PackID))
                    {
                        packInfoDic.TryGetValue(orderDetailInfo.PackID, out packInfo);
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                        packInfoDic.Add(orderDetailInfo.PackID, packInfo);
                    }
                    SkuInfo skuInfo = null;
                    if (skuInfoDic.ContainsKey(orderDetailInfo.OwnerID + orderDetailInfo.SkuID))
                    {
                        skuInfoDic.TryGetValue(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, out skuInfo);
                    }
                    else
                    {
                        skuInfo = skuDA.GetSkuByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                        skuInfoDic.Add(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, skuInfo);
                    }
                    bool successFlag = false;
                    string preallocatedResult = this.PreallocatedByOrderDetail(orderDetailInfo, orderDetailBLL, preAllocateRuleInfo, packInfo, skuInfo, updatedBy, whLoginID, ref successFlag);
                    if (!successFlag)
                    {
                        failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_024", this.pubParasInfo.UserLanguage);
                    }
                    else
                    {
                        List<AllocateRuleDetailInfo> allocateRuleDetailInfos = allocateRuleDetailDA.GetAllocateRuleDetailListByID(orderDetailInfo.AllocateRuleID, whLoginID, this.pubParasInfo);
                        if ((allocateRuleDetailInfos != null) && (allocateRuleDetailInfos.Count > 0))
                        {
                            decimal totalAllocatedQty = 0M;
                            int failCount = 0;
                            int strategyFailCounter = 0;
                            foreach (AllocateRuleDetailInfo allocateRuleDetailInfo in allocateRuleDetailInfos)
                            {
                                if (allocateRuleDetailInfo.IsActive == "Y")
                                {
                                    List<PreallocatePickDetailInfo> preallocatePickDetailInfos = preAllocatePickDetailDA.GetPreallocatePickDetailListByAllocateUomID(orderID, orderDetailInfo.LineID, allocateRuleDetailInfo.UomID, whLoginID);
                                    if ((preallocatePickDetailInfos != null) && (preallocatePickDetailInfos.Count > 0))
                                    {
                                        string temp2 = string.Empty;
                                        foreach (PreallocatePickDetailInfo preallocatePickDetailInfo in preallocatePickDetailInfos)
                                        {
                                            temp2 = this.AllocatedByPreallocatePickDetailInfo(preallocatePickDetailInfo, allocateRuleDetailInfo, orderDetailInfo, packInfo, ref totalAllocatedQty, updatedBy, whLoginID);
                                        }
                                        if (string.IsNullOrEmpty(temp2))
                                        {
                                            failCount++;
                                        }
                                    }
                                    else
                                    {
                                        strategyFailCounter++;
                                    }
                                }
                            }
                            if ((failCount == allocateRuleDetailInfos.Count) && ((failCount > 0) && (failCount <= allocateRuleDetailInfos.Count)))
                            {
                                failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_024", this.pubParasInfo.UserLanguage);
                            }
                            else if (strategyFailCounter == allocateRuleDetailInfos.Count)
                            {
                                failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_023", this.pubParasInfo.UserLanguage);
                            }
                            else
                            {
                                successMsg = successMsg + orderDetailInfo.LineID.ToString() + ",";
                            }
                            string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                            if (orderDetailInfo.BatchFlag == "Y")
                            {
                                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, updatedBy, whLoginID);
                            }
                            orderDetailDA.UpdateOrderDetailStatusAndQty(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, totalAllocatedQty, updatedBy, OrderDetailUpdateType.AllocatedQty, whLoginID);
                            this.UpdateSalesOrderDetailStatusAndQty(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                        }
                        else
                        {
                            failMsg = failMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_022", this.pubParasInfo.UserLanguage);
                        }
                    }
                }
                string orderStatus = orderBll.GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, updatedBy, whLoginID);
            }
            successMsg = string.IsNullOrEmpty(successMsg) ? "" : (PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + successMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_021", this.pubParasInfo.UserLanguage));
            failMsg = string.IsNullOrEmpty(failMsg) ? "" : (" //" + failMsg);
            return (successMsg + failMsg);
        }

        public string BatchAutoAllocate(List<string> orderIDS, string updatedBy)
        {
            string result = string.Empty;
            if ((orderIDS != null) && (orderIDS.Count > 0))
            {
                for (int i = 0; i < orderIDS.Count; i++)
                {
                    string temp = this.AutoAllocate(orderIDS[i], updatedBy);
                    if (!string.IsNullOrEmpty(temp))
                    {
                        result = result + orderIDS[i] + ":" + temp;
                    }
                }
            }
            return result;
        }

        private string BatchAutoAllocateForWave(string batchOrderID, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(batchOrderID, whLoginID);
            if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
            {
                for (int i = 0; i < waveDetailInfos.Count; i++)
                {
                    if (!string.IsNullOrEmpty(this.AutoAllocate(waveDetailInfos[i].OrderID, updatedBy)))
                    {
                        temp = temp + waveDetailInfos[i].OrderID + ",";
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchAutoAllocateOrders(string[] arr_orders, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            for (int i = 0; i < arr_orders.Length; i++)
            {
                if (!string.IsNullOrEmpty(this.AutoAllocate(arr_orders[i], updatedBy)))
                {
                    temp = temp + arr_orders[i] + ",";
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchAutoPreAllocateForWave(string batchOrderID, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(batchOrderID, whLoginID);
            if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
            {
                for (int i = 0; i < waveDetailInfos.Count; i++)
                {
                    if (!string.IsNullOrEmpty(this.AutoPreAllocate(waveDetailInfos[i].OrderID, updatedBy)))
                    {
                        temp = temp + waveDetailInfos[i].OrderID + ",";
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchAutoPreAllocateOrders(string[] arr_orders, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            for (int i = 0; i < arr_orders.Length; i++)
            {
                if (!string.IsNullOrEmpty(this.AutoPreAllocate(arr_orders[i], updatedBy)))
                {
                    temp = temp + arr_orders[i] + ",";
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string BatchOrderActions(string batchOrderID, string batchOrderType, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string CS40001 = batchOrderType.ToUpper();
            if (CS40001 == null)
            {
                return temp;
            }
            if (!(CS40001 == "PREALLOCATION"))
            {
                if (CS40001 != "ALLOCATION")
                {
                    if (CS40001 == "REVERTPREALLOCATION")
                    {
                        return this.BatchRevertPreAllocate(batchOrderID, updatedBy, whLoginID);
                    }
                    if (CS40001 == "REVERTALLOCATION")
                    {
                        return this.BatchRevertAllocate(batchOrderID, updatedBy, whLoginID);
                    }
                    if (CS40001 != "RELEASETASKS")
                    {
                        return temp;
                    }
                    return this.BatchReleasePickTasks(batchOrderID, updatedBy, whLoginID);
                }
            }
            else
            {
                return this.BatchAutoPreAllocateForWave(batchOrderID, updatedBy, whLoginID);
            }
            return this.BatchAutoAllocateForWave(batchOrderID, updatedBy, whLoginID);
        }

        public string BatchOrdersActions(string orders, string batchOrderType, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string[] arr_orders = orders.Split(new char[] { ',' });
            string CS40002 = batchOrderType.ToUpper();
            if (CS40002 == null)
            {
                return temp;
            }
            if (!(CS40002 == "PREALLOCATION"))
            {
                if (CS40002 != "ALLOCATION")
                {
                    if (CS40002 == "REVERTPREALLOCATION")
                    {
                        return this.BatchRevertPreAllocateOrders(arr_orders, updatedBy, whLoginID);
                    }
                    if (CS40002 == "REVERTALLOCATION")
                    {
                        return this.BatchRevertAllocateOrders(arr_orders, updatedBy, whLoginID);
                    }
                    if (CS40002 != "RELEASETASKS")
                    {
                        return temp;
                    }
                    return this.BatchReleasePickTasksOrders(arr_orders, updatedBy, whLoginID);
                }
            }
            else
            {
                return this.BatchAutoPreAllocateOrders(arr_orders, updatedBy, whLoginID);
            }
            return this.BatchAutoAllocateOrders(arr_orders, updatedBy, whLoginID);
        }

        public string BatchPreAllocate(string orderID, List<string> orderLineIDS, string updatedBy)
        {
            string successMsg = string.Empty;
            string failMsg = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = " AND OD.STATUS IN ('NEW','PARTPRE-ALLOCATED','PRE-ALLOCATED') AND OD.LINE_ID IN ('";
            if ((orderLineIDS != null) && (orderLineIDS.Count > 0))
            {
                for (int i = 0; i < orderLineIDS.Count; i++)
                {
                    where = where + orderLineIDS[i] + "','";
                }
                where = where.Substring(0, where.Length - 2) + ")";
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("F7100_010", this.pubParasInfo.UserLanguage);
            }
            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                Dictionary<string, PreallocateRuleInfo> preallocateRuleInfoDic = new Dictionary<string, PreallocateRuleInfo>();
                Dictionary<string, PackInfo> packInfoDic = new Dictionary<string, PackInfo>();
                Dictionary<string, SkuInfo> skuInfoDic = new Dictionary<string, SkuInfo>();
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    string CS00003;
                    if (!string.IsNullOrEmpty(orderDetailInfo.PreallocateRuleID))
                    {
                        PreallocateRuleInfo preAllocateRuleInfo = null;
                        if (preallocateRuleInfoDic.ContainsKey(orderDetailInfo.PreallocateRuleID))
                        {
                            preallocateRuleInfoDic.TryGetValue(orderDetailInfo.PreallocateRuleID, out preAllocateRuleInfo);
                        }
                        else
                        {
                            preAllocateRuleInfo = preAllocateRuleDA.GetPreallocateRuleByID(orderDetailInfo.PreallocateRuleID, whLoginID);
                            if (preAllocateRuleInfo != null)
                            {
                                preAllocateRuleInfo.PreallocateRuleDetailInfos = preAllocateRuleDetailDA.GetPreallocateRuleDetailListByID(preAllocateRuleInfo.PreallocateRuleID, whLoginID, this.pubParasInfo);
                                preallocateRuleInfoDic.Add(orderDetailInfo.PreallocateRuleID, preAllocateRuleInfo);
                            }
                            else
                            {
                                CS00003 = failMsg;
                                failMsg = CS00003 + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_015", this.pubParasInfo.UserLanguage) + ",";
                                continue;
                            }
                        }
                        PackInfo packInfo = null;
                        if (packInfoDic.ContainsKey(orderDetailInfo.PackID))
                        {
                            packInfoDic.TryGetValue(orderDetailInfo.PackID, out packInfo);
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(orderDetailInfo.PackID, whLoginID);
                            packInfoDic.Add(orderDetailInfo.PackID, packInfo);
                        }
                        SkuInfo skuInfo = null;
                        if (skuInfoDic.ContainsKey(orderDetailInfo.OwnerID + orderDetailInfo.SkuID))
                        {
                            skuInfoDic.TryGetValue(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, out skuInfo);
                        }
                        else
                        {
                            skuInfo = skuDA.GetSkuByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                            skuInfoDic.Add(orderDetailInfo.OwnerID + orderDetailInfo.SkuID, skuInfo);
                        }
                        bool successFlag = false;
                        string temp2 = this.PreallocatedByOrderDetail(orderDetailInfo, orderDetailBLL, preAllocateRuleInfo, packInfo, skuInfo, updatedBy, whLoginID, ref successFlag);
                        if (successFlag)
                        {
                            successMsg = successMsg + orderDetailInfo.LineID.ToString() + ",";
                            if (orderDetailInfo.BatchFlag == "Y")
                            {
                                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderDetailInfo.LineID.ToString(), orderDetailInfo.Status, updatedBy, whLoginID);
                            }
                        }
                        else
                        {
                            failMsg = failMsg + temp2 + ",";
                        }
                    }
                    else
                    {
                        CS00003 = failMsg;
                        failMsg = CS00003 + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_016", this.pubParasInfo.UserLanguage) + ",";
                        continue;
                    }
                }
                string orderStatus = new OrdersBLL().GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, updatedBy, whLoginID);
            }
            failMsg = string.IsNullOrEmpty(failMsg) ? "" : (" //" + failMsg);
            successMsg = string.IsNullOrEmpty(successMsg) ? "" : (PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + successMsg + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_012", this.pubParasInfo.UserLanguage));
            return (successMsg + failMsg);
        }

        private string BatchReleasePickTasks(string batchOrderID, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(batchOrderID, whLoginID);
            if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
            {
                for (int i = 0; i < waveDetailInfos.Count; i++)
                {
                    List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(waveDetailInfos[i].OrderID, PickDetailStatus.New, whLoginID);
                    if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.ReleasePickTasks(pickDetailID, updatedBy)))
                    {
                        temp = temp + waveDetailInfos[i].OrderID + ",";
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchReleasePickTasksOrders(string[] arr_orders, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            for (int i = 0; i < arr_orders.Length; i++)
            {
                List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(arr_orders[i], PickDetailStatus.New, whLoginID);
                if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.ReleasePickTasks(pickDetailID, updatedBy)))
                {
                    temp = temp + arr_orders[i] + ",";
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchRevertAllocate(string batchOrderID, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(batchOrderID, whLoginID);
            if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
            {
                for (int i = 0; i < waveDetailInfos.Count; i++)
                {
                    List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(waveDetailInfos[i].OrderID, PickDetailStatus.New, whLoginID);
                    if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.RevertAllocate(pickDetailID, updatedBy)))
                    {
                        temp = temp + waveDetailInfos[i].OrderID + ",";
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchRevertAllocateOrders(string[] arr_orders, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            for (int i = 0; i < arr_orders.Length; i++)
            {
                List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(arr_orders[i], PickDetailStatus.New, whLoginID);
                if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.RevertAllocate(pickDetailID, updatedBy)))
                {
                    temp = temp + arr_orders[i] + ",";
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchRevertPreAllocate(string batchOrderID, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(batchOrderID, whLoginID);
            if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
            {
                for (int i = 0; i < waveDetailInfos.Count; i++)
                {
                    List<string> orderLineIDS = ordersDA.GetOrderLineIDsByOrderID(waveDetailInfos[i].OrderID, whLoginID);
                    if (((orderLineIDS != null) && (orderLineIDS.Count > 0)) && !string.IsNullOrEmpty(this.RevertPreAllocate(waveDetailInfos[i].OrderID, orderLineIDS, updatedBy)))
                    {
                        temp = temp + waveDetailInfos[i].OrderID + ",";
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        private string BatchRevertPreAllocateOrders(string[] arr_orders, string updatedBy, string whLoginID)
        {
            string temp = string.Empty;
            for (int i = 0; i < arr_orders.Length; i++)
            {
                List<string> orderLineIDS = ordersDA.GetOrderLineIDsByOrderID(arr_orders[i], whLoginID);
                if (((orderLineIDS != null) && (orderLineIDS.Count > 0)) && !string.IsNullOrEmpty(this.RevertPreAllocate(arr_orders[i], orderLineIDS, updatedBy)))
                {
                    temp = temp + arr_orders[i] + ",";
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string CancelShipping(List<string> pickDetailID)
        {
            SysSettingInfo sysSettingInfo = sysSettingDA.GetSysSettingByID("ShipmentReversalToPU", this.dataBaseID[0], this.pubParasInfo);
            if (sysSettingInfo != null)
            {
                if (sysSettingInfo.Value == "Y")
                {
                    return this.CancelShippingToPicking(pickDetailID);
                }
                return this.CancelShippingToOrderNew(pickDetailID);
            }
            return this.CancelShippingToOrderNew(pickDetailID);
        }

        public string CancelShippingByOrderID(List<string> orderID)
        {
            string temp = string.Empty;
            for (int i = 0; orderID.Count > i; i++)
            {
                List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(orderID[i], PickDetailStatus.Shipped, this.dataBaseID[0]);
                this.CancelShipping(pickDetailID);
            }
            return temp;
        }

        public string CancelShippingByOrderIDOrderLineID(string orderID, List<string> LineID)
        {
            string temp = string.Empty;
            for (int i = 0; LineID.Count > i; i++)
            {
                List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderLineID(orderID, LineID[i], PickDetailStatus.Shipped, this.dataBaseID[0]);
                temp = this.CancelShipping(pickDetailID);
            }
            return temp;
        }

        public string CancelShippingToOrderNew(List<string> pickDetailID)
        {
            WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                List<AdjustmentInfo> AdjustmentList = new List<AdjustmentInfo>();
                int i = 0;
                while (i < pickDetailID.Count)
                {
                    PickDetailInfo pickDetailInfo = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    if ((pickDetailInfo != null) && (pickDetailInfo.Status == PickDetailStatus.Shipped))
                    {
                        AdjustmentDetailInfo adjustmentDetailInfo;
                        invTransDA.UpdateTransStatusByDocID(dataBase, tran, pickDetailInfo.PickDetailID, TransType.Shipment, TransSourceType.PickingUpdate, this.pubParasInfo.UserID, TransStatus.Cancelled, whLoginID);
                        string strTransID = this.InsertConfirmPickedAndShippedTrans(dataBase, tran, pickDetailInfo, "SHIPMENTREVERAL", "", whLoginID);
                        AdjustmentInfo adjustmentInfo = new AdjustmentInfo {
                            AdjustmentID = pickDetailInfo.OrderID,
                            OwnerID = pickDetailInfo.OwnerID
                        };
                        if (AdjustmentList.Contains(adjustmentInfo))
                        {
                            foreach (AdjustmentInfo info in AdjustmentList)
                            {
                                if (info.AdjustmentID == adjustmentInfo.AdjustmentID)
                                {
                                    if (info.AdjustmentDetail == null)
                                    {
                                        info.AdjustmentDetail = new List<AdjustmentDetailInfo>();
                                    }
                                    adjustmentDetailInfo = new AdjustmentDetailInfo {
                                        SkuID = pickDetailInfo.SkuID,
                                        OwnerID = pickDetailInfo.OwnerID,
                                        PackID = pickDetailInfo.PackID,
                                        UomID = pickDetailInfo.UomID,
                                        Loc = pickDetailInfo.Loc,
                                        Lot = pickDetailInfo.Lot,
                                        LpnID = pickDetailInfo.LpnID,
                                        Qty = pickDetailInfo.Qty * -1M,
                                        TransID = strTransID,
                                        AdjustmentDate = DateTime.Now,
                                        ReceiptID = pickDetailInfo.OrderID,
                                        ReceiptLineID = pickDetailInfo.OrderLineID,
                                        ReferenceID = pickDetailInfo.PickDetailID,
                                        Remark = "",
                                        ReasonCode = AdjReasonCode.UnShipping
                                    };
                                    info.AdjustmentDetail.Add(adjustmentDetailInfo);
                                }
                                break;
                            }
                        }
                        else
                        {
                            adjustmentInfo.AdjustmentDetail = new List<AdjustmentDetailInfo>();
                            adjustmentDetailInfo = new AdjustmentDetailInfo {
                                SkuID = pickDetailInfo.SkuID,
                                OwnerID = pickDetailInfo.OwnerID,
                                PackID = pickDetailInfo.PackID,
                                UomID = pickDetailInfo.UomID,
                                Loc = pickDetailInfo.Loc,
                                Lot = pickDetailInfo.Lot,
                                LpnID = pickDetailInfo.LpnID,
                                Qty = pickDetailInfo.Qty * -1M,
                                TransID = strTransID,
                                ReceiptID = pickDetailInfo.OrderID,
                                ReceiptLineID = pickDetailInfo.OrderLineID,
                                ReferenceID = pickDetailInfo.PickDetailID,
                                Remark = "",
                                ReasonCode = AdjReasonCode.UnShipping
                            };
                            adjustmentInfo.AdjustmentDetail.Add(adjustmentDetailInfo);
                            AdjustmentList.Add(adjustmentInfo);
                        }
                        InvLotInfo invLotinfo = new InvLotInfo {
                            Lot = pickDetailInfo.Lot,
                            UpdatedBy = this.pubParasInfo.UserID,
                            Qty = pickDetailInfo.Qty
                        };
                        invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.UnShippedQty, whLoginID);
                        InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                            Lot = pickDetailInfo.Lot,
                            Loc = pickDetailInfo.Loc,
                            LpnID = pickDetailInfo.LpnID,
                            Qty = pickDetailInfo.Qty,
                            UpdatedBy = this.pubParasInfo.UserID
                        };
                        invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.UnShippedQty, whLoginID);
                        InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                            Loc = pickDetailInfo.Loc,
                            SkuID = pickDetailInfo.SkuID,
                            OwnerID = pickDetailInfo.OwnerID,
                            UpdatedBy = this.pubParasInfo.UserID,
                            Qty = pickDetailInfo.Qty
                        };
                        invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.UnShippedQty, whLoginID);
                        LpnInfo lpnInfo = new LpnInfo();
                        if (!string.IsNullOrEmpty(pickDetailInfo.LpnID))
                        {
                            lpnInfo = lpnDA.GetLpnByID(dataBase, tran, pickDetailInfo.LpnID, whLoginID);
                            if (lpnInfo != null)
                            {
                                lpnInfo.Qty += pickDetailInfo.Qty;
                                lpnInfo.UpdatedBy = this.pubParasInfo.UserID;
                                lpnDA.UpdateLpn(dataBase, tran, lpnInfo, LpnUpdateType.Qty, whLoginID);
                            }
                        }
                        OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), whLoginID, this.pubParasInfo);
                        orderDetailInfo.ShippedQty -= pickDetailInfo.Qty;
                        string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                        orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty, this.pubParasInfo.UserID, OrderDetailUpdateType.UnShippedQty, whLoginID);
                        this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, pickDetailInfo.Qty * -1M, whLoginID, this.pubParasInfo);
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderDetailStatus, this.pubParasInfo.UserID, whLoginID);
                        OrdersInfo ordersInfo = ordersDA.GetOrdersByID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        string orderStatus = orderBll.GetOrderStatus(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo.OrderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                        this.UpdateSalesOrderStatus(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        wavebll.UpdateWaveStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID);
                        loadDetailDA.UpdateLoadDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                        if (!string.IsNullOrEmpty(pickDetailInfo.PreallocatePickDetailID))
                        {
                            if (preAllocatePickDetailDA.GetPreallocatePickDetailByID(dataBase, tran, pickDetailInfo.PreallocatePickDetailID, whLoginID).Qty > pickDetailInfo.Qty)
                            {
                                preAllocatePickDetailDA.UpdatePreAllocatePickDetailQty(dataBase, tran, pickDetailInfo.PreallocatePickDetailID, pickDetailInfo.Qty * -1M, this.pubParasInfo.UserID, whLoginID);
                            }
                            else
                            {
                                List<string> gInitLocal2 = new List<string> {
                                    pickDetailInfo.PreallocatePickDetailID
                                };
                                preAllocatePickDetailDA.DeletePreallocatePickDetail(dataBase, tran, gInitLocal2, whLoginID);
                            }
                        }
                        pickDetailDa.DeletePickDetailByID(dataBase, tran, pickDetailID[i], whLoginID);
                        temp = temp + pickDetailID[i] + ";";
                    }
                    i++;
                }
                if (AdjustmentList.Count > 0)
                {
                    foreach (AdjustmentInfo info in AdjustmentList)
                    {
                        string strAdjustmentID = string.Empty;
                        strAdjustmentID = commonMethod.GenNextNumStr(dataBase, tran, "ADJUSTMENT", whLoginID);
                        info.AdjustmentID = strAdjustmentID;
                        info.AdjustmentDate = DateTime.Now;
                        info.IsActive = "Y";
                        info.Remark = "";
                        info.CreatedBy = this.pubParasInfo.UserID;
                        info.UpdatedBy = info.CreatedBy;
                        adjustmentDA.InsertAdjustment(dataBase, tran, info, whLoginID);
                        for (i = 0; info.AdjustmentDetail.Count > i; i++)
                        {
                            info.AdjustmentDetail[i].AdjustmentID = strAdjustmentID;
                            info.AdjustmentDetail[i].AdjustmentDate = DateTime.Now;
                            info.AdjustmentDetail[i].LineID = (i + 1) * 10;
                            info.AdjustmentDetail[i].CreatedBy = info.CreatedBy;
                            info.AdjustmentDetail[i].UpdatedBy = info.CreatedBy;
                            adjustmentDetailDA.InsertAdjustmentDetail(dataBase, tran, info.AdjustmentDetail[i], whLoginID);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string CancelShippingToPicking(List<string> pickDetailID)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                List<AdjustmentInfo> AdjustmentList = new List<AdjustmentInfo>();
                int i = 0;
                while (i < pickDetailID.Count)
                {
                    PickDetailInfo pickDetailInfo = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    if ((pickDetailInfo != null) && (pickDetailInfo.Status == PickDetailStatus.Shipped))
                    {
                        AdjustmentDetailInfo adjustmentDetailInfo;
                        invTransDA.UpdateTransStatusByDocID(dataBase, tran, pickDetailInfo.PickDetailID, TransType.Shipment, TransSourceType.PickingUpdate, this.pubParasInfo.UserID, TransStatus.Cancelled, whLoginID);
                        string strTransID = this.InsertConfirmPickedAndShippedTrans(dataBase, tran, pickDetailInfo, "SHIPMENTREVERAL", "", whLoginID);
                        AdjustmentInfo adjustmentInfo = new AdjustmentInfo {
                            AdjustmentID = pickDetailInfo.OrderID,
                            OwnerID = pickDetailInfo.OwnerID
                        };
                        if (AdjustmentList.Contains(adjustmentInfo))
                        {
                            foreach (AdjustmentInfo info in AdjustmentList)
                            {
                                if (info.AdjustmentID == adjustmentInfo.AdjustmentID)
                                {
                                    if (info.AdjustmentDetail == null)
                                    {
                                        info.AdjustmentDetail = new List<AdjustmentDetailInfo>();
                                    }
                                    adjustmentDetailInfo = new AdjustmentDetailInfo {
                                        SkuID = pickDetailInfo.SkuID,
                                        OwnerID = pickDetailInfo.OwnerID,
                                        PackID = pickDetailInfo.PackID,
                                        UomID = pickDetailInfo.UomID,
                                        Loc = pickDetailInfo.Loc,
                                        Lot = pickDetailInfo.Lot,
                                        LpnID = pickDetailInfo.LpnID,
                                        Qty = pickDetailInfo.Qty * -1M,
                                        TransID = strTransID,
                                        AdjustmentDate = DateTime.Now,
                                        ReceiptID = pickDetailInfo.OrderID,
                                        ReceiptLineID = pickDetailInfo.OrderLineID,
                                        ReferenceID = pickDetailInfo.PickDetailID,
                                        Remark = "",
                                        ReasonCode = AdjReasonCode.UnShipping
                                    };
                                    info.AdjustmentDetail.Add(adjustmentDetailInfo);
                                }
                                break;
                            }
                        }
                        else
                        {
                            adjustmentInfo.AdjustmentDetail = new List<AdjustmentDetailInfo>();
                            adjustmentDetailInfo = new AdjustmentDetailInfo {
                                SkuID = pickDetailInfo.SkuID,
                                OwnerID = pickDetailInfo.OwnerID,
                                PackID = pickDetailInfo.PackID,
                                UomID = pickDetailInfo.UomID,
                                Loc = pickDetailInfo.Loc,
                                Lot = pickDetailInfo.Lot,
                                LpnID = pickDetailInfo.LpnID,
                                Qty = pickDetailInfo.Qty * -1M,
                                TransID = strTransID,
                                ReceiptID = pickDetailInfo.OrderID,
                                ReceiptLineID = pickDetailInfo.OrderLineID,
                                ReferenceID = pickDetailInfo.PickDetailID,
                                Remark = "",
                                ReasonCode = AdjReasonCode.UnShipping
                            };
                            adjustmentInfo.AdjustmentDetail.Add(adjustmentDetailInfo);
                            AdjustmentList.Add(adjustmentInfo);
                        }
                        InvLotInfo invLotinfo = new InvLotInfo {
                            Lot = pickDetailInfo.Lot,
                            UpdatedBy = this.pubParasInfo.UserID,
                            Qty = pickDetailInfo.Qty
                        };
                        invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.UnShippedQtyToPicked, whLoginID);
                        InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                            Lot = pickDetailInfo.Lot,
                            Loc = pickDetailInfo.ToLoc,
                            LpnID = pickDetailInfo.LpnID,
                            Qty = pickDetailInfo.Qty,
                            UpdatedBy = this.pubParasInfo.UserID
                        };
                        invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.UnShippedQtyToPicked, whLoginID);
                        InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                            Loc = pickDetailInfo.ToLoc,
                            SkuID = pickDetailInfo.SkuID,
                            OwnerID = pickDetailInfo.OwnerID,
                            UpdatedBy = this.pubParasInfo.UserID,
                            Qty = pickDetailInfo.Qty
                        };
                        invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.UnShippedQtyToPicked, whLoginID);
                        LpnInfo lpnInfo = new LpnInfo();
                        if (!string.IsNullOrEmpty(pickDetailInfo.LpnID))
                        {
                            lpnInfo = lpnDA.GetLpnByID(dataBase, tran, pickDetailInfo.LpnID, whLoginID);
                            if (lpnInfo != null)
                            {
                                lpnInfo.Qty += pickDetailInfo.Qty;
                                lpnInfo.UpdatedBy = this.pubParasInfo.UserID;
                                lpnDA.UpdateLpn(dataBase, tran, lpnInfo, LpnUpdateType.Qty, whLoginID);
                            }
                        }
                        OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), whLoginID, this.pubParasInfo);
                        orderDetailInfo.ShippedQty -= pickDetailInfo.Qty;
                        orderDetailInfo.PickedQty += pickDetailInfo.Qty;
                        string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                        orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty, this.pubParasInfo.UserID, OrderDetailUpdateType.UnShippedQtyToPicked, whLoginID);
                        this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, pickDetailInfo.Qty * -1M, whLoginID, this.pubParasInfo);
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderDetailStatus, this.pubParasInfo.UserID, whLoginID);
                        OrdersInfo ordersInfo = ordersDA.GetOrdersByID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        string orderStatus = orderBll.GetOrderStatus(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo.OrderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                        this.UpdateSalesOrderStatus(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        wavebll.UpdateWaveStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID);
                        loadDetailDA.UpdateLoadDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                        pickDetailDa.UpdatePickDetailStatus(dataBase, tran, pickDetailID[i], PickDetailStatus.Picked, this.pubParasInfo.UserID, whLoginID);
                        temp = temp + pickDetailID[i] + ";";
                    }
                    i++;
                }
                if (AdjustmentList.Count > 0)
                {
                    foreach (AdjustmentInfo info in AdjustmentList)
                    {
                        string strAdjustmentID = string.Empty;
                        strAdjustmentID = commonMethod.GenNextNumStr(dataBase, tran, "ADJUSTMENT", whLoginID);
                        info.AdjustmentID = strAdjustmentID;
                        info.AdjustmentDate = DateTime.Now;
                        info.IsActive = "Y";
                        info.Remark = "";
                        info.CreatedBy = this.pubParasInfo.UserID;
                        info.UpdatedBy = info.CreatedBy;
                        adjustmentDA.InsertAdjustment(dataBase, tran, info, whLoginID);
                        for (i = 0; info.AdjustmentDetail.Count > i; i++)
                        {
                            info.AdjustmentDetail[i].AdjustmentID = strAdjustmentID;
                            info.AdjustmentDetail[i].AdjustmentDate = DateTime.Now;
                            info.AdjustmentDetail[i].LineID = (i + 1) * 10;
                            info.AdjustmentDetail[i].CreatedBy = info.CreatedBy;
                            info.AdjustmentDetail[i].UpdatedBy = info.CreatedBy;
                            adjustmentDetailDA.InsertAdjustmentDetail(dataBase, tran, info.AdjustmentDetail[i], whLoginID);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        private ReceiptInfo ChangeOrdersInfo2ReceiptInfo(DataBase dataBase, DbTransaction tran, OrdersInfo ordersInfo, List<PickDetailInfo> pickDetailInfos, string whLoginID)
        {
            ReceiptInfo receiptInfo = new ReceiptInfo();
            List<ReceiptDetailInfo> receiptDetailTemp = null;
            if (ordersInfo != null)
            {
                List<string> descWbID = commonMethod.GetDataBaseID(dataBase, tran, ordersInfo.DestWhDbID);
                string receiptID = commonMethod.GenNextNumStr(dataBase, tran, "RECEIPT", descWbID[0]);
                receiptInfo.ReceiptID = receiptID;
                receiptInfo.ReceiptType = ReceiptTypes.Transfer;
                receiptInfo.OwnerID = ordersInfo.OwnerID;
                receiptInfo.PoID = "";
                receiptInfo.ExternalReceiptID = ordersInfo.OrderID;
                receiptInfo.ExternalReceiptId2 = ordersInfo.IntransitID;
                receiptInfo.ExpectedReceiptDate = ordersInfo.ActualShipDate;
                receiptInfo.Status = ReceiptStatus.New;
                receiptInfo.LottableMatchRequired = "N";
                receiptInfo.IsPalletized = "N";
                receiptInfo.IsActive = "Y";
                receiptInfo.ArrivalDate = ordersInfo.DeliveryDate;
                receiptInfo.CreatedBy = this.pubParasInfo.UserID;
                receiptInfo.UpdatedBy = this.pubParasInfo.UserID;
                receiptDetailTemp = this.ChangePickDetail2ReciptiDetail(dataBase, tran, pickDetailInfos, receiptID, whLoginID, ordersInfo.DestWhDbID);
                if ((receiptDetailTemp != null) && (receiptDetailTemp.Count > 0))
                {
                    receiptInfo.ReceiptDetailInfos = receiptDetailTemp;
                }
            }
            return receiptInfo;
        }

        private List<ReceiptDetailInfo> ChangePickDetail2ReciptiDetail(DataBase dataBase, DbTransaction tran, List<PickDetailInfo> pickDetailInfos, string strRceiptID, string whLoginID, string destWhDbID)
        {
            List<ReceiptDetailInfo> receiptDetailInfos = new List<ReceiptDetailInfo>();
            ReceiptDetailInfo receiptDetail = null;
            if ((pickDetailInfos != null) && (pickDetailInfos.Count > 0))
            {
                int i;
                List<PickDetailInfo> temp = new List<PickDetailInfo>();
                for (i = 0; i < pickDetailInfos.Count; i++)
                {
                    bool flag = false;
                    for (int j = 0; j < temp.Count; j++)
                    {
                        if (pickDetailInfos[i].Lot == temp[j].Lot)
                        {
                            PickDetailInfo local1 = temp[j];
                            local1.Qty += pickDetailInfos[i].Qty;
                            flag = true;
                            goto Label_00A5;
                        }
                    }
                Label_00A5:
                    if (!flag)
                    {
                        temp.Add(pickDetailInfos[i]);
                    }
                }
                for (i = 0; i < temp.Count; i++)
                {
                    receiptDetail = new ReceiptDetailInfo {
                        ReceiptID = strRceiptID,
                        ReceiptLineID = (i + 1) * 10,
                        OwnerID = temp[i].OwnerID,
                        ExternReceiptID = "",
                        ExternLineID = "",
                        SkuID = temp[i].SkuID,
                        AltSkuID = "",
                        LpnID = "",
                        ExpectedQty = temp[i].Qty,
                        AdjustedQty = 0.0M,
                        RejectedQty = 0.0M,
                        ReceivedQty = 0.0M,
                        PackID = temp[i].PackID
                    };
                    DbConfigInfo dbConfigInfo = dbConfigDA.GetDbConfigByID(dataBase, tran, destWhDbID);
                    SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, temp[i].OwnerID, temp[i].SkuID, dbConfigInfo.DbLoginID + ".");
                    PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuInfo.PackID, dbConfigInfo.DbLoginID + ".");
                    receiptDetail.UomID = packInfo.PackUom1;
                    receiptDetail.SkuDescr = skuInfo.Descr;
                    receiptDetail.ToLoc = "";
                    receiptDetail.ConditionCode = "OK";
                    receiptDetail.Udf1 = "";
                    receiptDetail.Udf2 = "";
                    receiptDetail.Udf3 = "";
                    receiptDetail.Udf4 = "";
                    receiptDetail.Udf5 = "";
                    receiptDetail.Udf6 = "";
                    receiptDetail.Udf7 = "";
                    receiptDetail.Udf8 = "";
                    receiptDetail.Udf9 = "";
                    receiptDetail.Udf10 = "";
                    LotAttributeInfo lotAttr = lotAttributeDA.GetLotAttributeByID(dataBase, tran, temp[i].Lot, whLoginID);
                    if (lotAttr != null)
                    {
                        ReceiptLotInfo receiptLotInfo = new ReceiptLotInfo {
                            LotAttr01 = lotAttr.LotAttr01,
                            LotAttr02 = lotAttr.LotAttr02,
                            LotAttr03 = lotAttr.LotAttr03,
                            LotAttr04 = lotAttr.LotAttr04,
                            LotAttr05 = lotAttr.LotAttr05,
                            LotAttr06 = lotAttr.LotAttr06,
                            LotAttr07 = lotAttr.LotAttr07,
                            LotAttr08 = lotAttr.LotAttr08,
                            LotAttr09 = lotAttr.LotAttr09,
                            LotAttr10 = lotAttr.LotAttr10,
                            ProduceDate = lotAttr.ProduceDate,
                            ExpiryDate = lotAttr.ExpiryDate,
                            ExternalLot = lotAttr.ExternalLot,
                            VendorID = lotAttr.VendorID,
                            ReceiptDate = lotAttr.ReceiptDate
                        };
                        receiptDetail.ReceiptLot = receiptLotInfo;
                    }
                    receiptDetail.Status = ReceiptStatus.New;
                    receiptDetail.CaseCnt = 0M;
                    receiptDetail.InnerPack = 0M;
                    receiptDetail.Pallet = 0M;
                    receiptDetail.OtherUnit1 = 0f;
                    receiptDetail.OtherUnit2 = 0f;
                    receiptDetail.ExtendedPrice = 0f;
                    receiptDetail.CreatedBy = temp[i].CreatedBy;
                    receiptDetail.UpdatedBy = temp[i].UpdatedBy;
                    receiptDetail.Cube = 0f;
                    receiptDetail.GrossWgt = 0f;
                    receiptDetail.NetWgt = 0f;
                    DataSet poPriceDS = ordersDA.GetUnitPriceAndPoIDByLot4Shipping(dataBase, tran, temp[i].Lot, whLoginID);
                    if (((poPriceDS != null) && (poPriceDS.Tables.Count > 0)) && (poPriceDS.Tables[0].Rows.Count > 0))
                    {
                        receiptDetail.UnitPrice = float.Parse(string.IsNullOrEmpty(poPriceDS.Tables[0].Rows[0]["UNIT_PRICE"].ToString()) ? "0" : poPriceDS.Tables[0].Rows[0]["UNIT_PRICE"].ToString());
                        receiptDetail.ExtendedPrice = receiptDetail.UnitPrice * Convert.ToSingle(receiptDetail.ExpectedQty);
                        receiptDetail.PoID = poPriceDS.Tables[0].Rows[0]["PO_ID"].ToString();
                        receiptDetail.PoLineID = int.Parse(string.IsNullOrEmpty(poPriceDS.Tables[0].Rows[0]["PO_LINE_ID"].ToString()) ? "0" : poPriceDS.Tables[0].Rows[0]["PO_LINE_ID"].ToString());
                    }
                    else
                    {
                        receiptDetail.UnitPrice = 0f;
                        receiptDetail.ExtendedPrice = 0f;
                        receiptDetail.PoID = "";
                        receiptDetail.PoLineID = 0;
                    }
                    receiptDetail.EffectiveDate = DateTime.Now;
                    receiptDetail.QcRequired = "N";
                    receiptDetailInfos.Add(receiptDetail);
                }
            }
            return receiptDetailInfos;
        }

        public bool CheckLocationAndQty(DataBase database, DbTransaction tran, string lot, string loc, string lpn, decimal qty)
        {
            bool temp = false;
            try
            {
                InvLotLocLpnInfo invLotLocLpnEntity = invLotLocLpnDA.GetInvLotLocLpnByID(database, tran, lot, loc, lpn, this.dataBaseID[0]);
                if (invLotLocLpnEntity != null)
                {
                    if (invLotLocLpnEntity.Status != InvHoldStatus.HOLD)
                    {
                        if (qty <= ((invLotLocLpnEntity.Qty - invLotLocLpnEntity.AllocatedQty) - invLotLocLpnEntity.PickedQty))
                        {
                            return true;
                        }
                        List<string> gInitLocal0 = new List<string> {
                            invLotLocLpnEntity.Loc
                        };
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_007", this.pubParasInfo.UserLanguage, gInitLocal0);
                        return temp;
                    }
                    List<string> gInitLocal1 = new List<string> {
                        invLotLocLpnEntity.Loc
                    };
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_008", this.pubParasInfo.UserLanguage, gInitLocal1);
                    return temp;
                }
                PublicMethod.GetInstance().ShowAlertMessage("F7100_009", this.pubParasInfo.UserLanguage);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public List<InvLotLocLpnInfo> CheckLocationQty4Allocation(ManualAllocateParams manualAllocateParams)
        {
            List<InvLotLocLpnInfo> tempinvLotLocLpnList = new List<InvLotLocLpnInfo>();
            LotAttributeInfo lotAttributeInfo = new LotAttributeInfo {
                OwnerID = manualAllocateParams.OwnerID,
                SkuID = manualAllocateParams.SkuID,
                LotAttr01 = manualAllocateParams.LotAttr01,
                LotAttr02 = manualAllocateParams.LotAttr02,
                LotAttr03 = manualAllocateParams.LotAttr03,
                LotAttr04 = manualAllocateParams.LotAttr04,
                LotAttr05 = manualAllocateParams.LotAttr05,
                LotAttr06 = manualAllocateParams.LotAttr06,
                LotAttr07 = manualAllocateParams.LotAttr07,
                LotAttr08 = manualAllocateParams.LotAttr08,
                LotAttr09 = manualAllocateParams.LotAttr09,
                LotAttr10 = manualAllocateParams.LotAttr10,
                ProduceDate = manualAllocateParams.ProduceDate,
                ExpiryDate = manualAllocateParams.ExpiryDate,
                ExternalLot = manualAllocateParams.ExternalLot,
                VendorID = manualAllocateParams.VendorID
            };
            List<InvLotInfo> invLotInfo = this.GetInvLotByLotAttribute4ManualAllocate(lotAttributeInfo, this.dataBaseID[0]);
            if ((invLotInfo != null) && (invLotInfo.Count > 0))
            {
                int i;
                string lot = string.Empty;
                for (i = 0; i < invLotInfo.Count; i++)
                {
                    lot = lot + "'" + invLotInfo[i].Lot + "',";
                }
                lot = lot.Substring(0, lot.Length - 1);
                List<string> sqlWhere = new List<string>();
                if (!string.IsNullOrEmpty(manualAllocateParams.Loc))
                {
                    sqlWhere.Add(" A.LOC = '" + manualAllocateParams.Loc + "'");
                }
                if (!string.IsNullOrEmpty(manualAllocateParams.OwnerID))
                {
                    sqlWhere.Add(" A.OWNER_ID ='" + manualAllocateParams.OwnerID + "'");
                }
                if (!string.IsNullOrEmpty(manualAllocateParams.SkuID))
                {
                    sqlWhere.Add(" A.SKU_ID ='" + manualAllocateParams.SkuID + "'");
                }
                if (!string.IsNullOrEmpty(lot))
                {
                    sqlWhere.Add(" A.LOT IN (" + lot + ")");
                }
                if (!string.IsNullOrEmpty(manualAllocateParams.Lpn))
                {
                    sqlWhere.Add(" A.LPN_ID ='" + manualAllocateParams.Lpn + "'");
                }
                sqlWhere.Add(" A.QTY > 0 ");
                sqlWhere.Add(" A.STATUS <> 'HOLD' ");
                sqlWhere.Add(" A.QTY-A.ALLOCATED_QTY-A.PICKED_QTY-A.EXPECTED_QTY- A.PICKINPROCESS_QTY- A.PENDING_MOVE_IN > 0 ");
                InvLotLocLpnQueryEntity LotLocLpnEntity = new InvLotLocLpnQueryEntity {
                    IsGetAll = true,
                    CurrentPage = "0",
                    PageSize = "100",
                    SortField = "L.RECEIPT_DATE",
                    SortDirection = "DESC"
                };
                List<InvLotLocLpnInfo> invLotLocLpnList = new List<InvLotLocLpnInfo>();
                DataSet totalInfo = DataAccess.CreateInvLotLocLpnDA().GetInvLotLocLpnByQueryList(sqlWhere, LotLocLpnEntity, this.dataBaseID[0], this.pubParasInfo);
                if ((totalInfo == null) || (totalInfo.Tables[0].Rows.Count <= 0))
                {
                    return tempinvLotLocLpnList;
                }
                invLotLocLpnList = this.AddInvLotLocLpn2List(invLotLocLpnList, totalInfo.Tables[0]);
                decimal tempDecqty = new InboundHelper().ExchangeUom(manualAllocateParams.PackID, manualAllocateParams.UomID, manualAllocateParams.Qty, "W", this.dataBaseID[0]);
                if (invLotLocLpnList.Count <= 0)
                {
                    return tempinvLotLocLpnList;
                }
                for (i = 0; i < invLotLocLpnList.Count; i++)
                {
                    decimal remainQty = 0M;
                    if (invLotLocLpnList[i].AvailableQty > 0M)
                    {
                        InvLotLocLpnInfo invlotloclpn = new InvLotLocLpnInfo();
                        remainQty = invLotLocLpnList[i].AvailableQty - tempDecqty;
                        if (remainQty >= 0M)
                        {
                            invlotloclpn = invLotLocLpnList[i];
                            invlotloclpn.Qty = tempDecqty;
                            tempinvLotLocLpnList.Add(invlotloclpn);
                            return tempinvLotLocLpnList;
                        }
                        tempDecqty -= invLotLocLpnList[i].AvailableQty;
                        invlotloclpn = invLotLocLpnList[i];
                        invlotloclpn.Qty = invLotLocLpnList[i].AvailableQty;
                        tempinvLotLocLpnList.Add(invlotloclpn);
                    }
                }
            }
            return tempinvLotLocLpnList;
        }

        public string ClosedByOrderID(List<string> orderID)
        {
            int i;
            List<BillingCredenceInfo> billingCredenceListInfo;
            string strtemp = string.Empty;
            BillingOrderBLL billingOrderBLL = new BillingOrderBLL(this.pubParasInfo);
            Dictionary<string, List<BillingCredenceInfo>> billingCredenceListObjects = new Dictionary<string, List<BillingCredenceInfo>>();
            for (i = 0; orderID.Count > i; i++)
            {
                billingCredenceListInfo = billingOrderBLL.GetOutboundBillingCredenceListInfo(orderID[i]);
                billingCredenceListObjects.Add(orderID[i], billingCredenceListInfo);
            }
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (i = 0; orderID.Count > i; i++)
                {
                    List<OrderDetailInfo> orderDetailInfo = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, orderID[i], this.dataBaseID[0], this.pubParasInfo);
                    if ((orderDetailInfo != null) && (orderDetailInfo.Count > 0))
                    {
                        foreach (OrderDetailInfo info in orderDetailInfo)
                        {
                            if (info.PreallocatedQty > 0M)
                            {
                                throw new Exception(string.Concat(new object[] { "出库单:", info.OrderID, " 行号: ", info.LineID, " 已有预分配数量,无法被关闭!" }));
                            }
                            if (info.AllocatedQty > 0M)
                            {
                                throw new Exception(string.Concat(new object[] { "出库单:", info.OrderID, " 行号: ", info.LineID, " 已有分配数量,无法被关闭!" }));
                            }
                            if (info.PickedQty > 0M)
                            {
                                throw new Exception(string.Concat(new object[] { "出库单:", info.OrderID, " 行号: ", info.LineID, " 已有拣货数量,无法被关闭!" }));
                            }
                        }
                    }
                    orderDetailDA.UpdateOrderDetailStatus(dataBase, tran, orderID[i], OrderStatus.Closed, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    ordersDA.UpdateOrdersStatus(dataBase, tran, orderID[i], OrderStatus.Closed, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    if (billingCredenceListObjects.ContainsKey(orderID[i]))
                    {
                        billingCredenceListInfo = new List<BillingCredenceInfo>();
                        billingCredenceListObjects.TryGetValue(orderID[i], out billingCredenceListInfo);
                        billingOrderBLL.GenerateBillingCredenceByCloseOrder(dataBase, tran, orderID[i], "OutBound", billingCredenceListInfo);
                    }
                    strtemp = strtemp + orderID[i] + " ;";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strtemp;
        }

        public string ConfirmPicked(List<string> pickDetailID, List<string> toLoc, string updateBy)
        {
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL(this.pubParasInfo);
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            List<string> orderIDList = new List<string>();
            try
            {
                int i;
                for (i = 0; i < pickDetailID.Count; i++)
                {
                    if ((toLoc == null) || locationDA.CheckLocationIDUnique(toLoc[i], whLoginID))
                    {
                        PickDetailInfo pickDetailInfo = pickDetailDa.GetPickDetailByID(pickDetailID[i], whLoginID, this.pubParasInfo);
                        if ((pickDetailInfo != null) && ((pickDetailInfo.Status == PickDetailStatus.New) || (pickDetailInfo.Status == PickDetailStatus.Released)))
                        {
                            if (toLoc != null)
                            {
                                pickDetailInfo.ToLoc = toLoc[i];
                            }
                            pickDetailInfo.Status = PickDetailStatus.Picked;
                            pickDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                            if (!invLotLocLpnDA.CheckInvLotLocLpnIDUnique(pickDetailInfo.Lot, pickDetailInfo.ToLoc, pickDetailInfo.LpnID, whLoginID))
                            {
                                InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                    Lot = pickDetailInfo.Lot,
                                    Loc = pickDetailInfo.ToLoc,
                                    LpnID = pickDetailInfo.LpnID,
                                    OwnerID = pickDetailInfo.OwnerID,
                                    SkuID = pickDetailInfo.SkuID,
                                    CreatedBy = this.pubParasInfo.UserID,
                                    UpdatedBy = this.pubParasInfo.UserID,
                                    ArchiveDate = DateTime.Parse("2000-01-01")
                                };
                                invLotLocLpnDA.InsertInvLotLocLpn(invLotLocLpnInfo, whLoginID);
                            }
                            if (!invSkuLocDA.CheckInvSkuLocIDUnique(pickDetailInfo.OwnerID, pickDetailInfo.SkuID, pickDetailInfo.ToLoc, whLoginID))
                            {
                                InvSkuLocInfo invSkuLocInfo = new InvSkuLocInfo {
                                    OwnerID = pickDetailInfo.OwnerID,
                                    SkuID = pickDetailInfo.SkuID,
                                    Loc = pickDetailInfo.ToLoc,
                                    CreatedBy = this.pubParasInfo.UserID,
                                    UpdatedBy = this.pubParasInfo.UserID
                                };
                                invSkuLocDA.InsertInvSkuLoc(invSkuLocInfo, whLoginID);
                            }
                            if (orderDetailDA.ConfirmPicked(pickDetailInfo, whLoginID))
                            {
                                this.InsertConfirmPickedAndShippedTrans(pickDetailInfo, "Picked", "", whLoginID);
                                if (!orderIDList.Contains(pickDetailInfo.OrderID))
                                {
                                    orderIDList.Add(pickDetailInfo.OrderID);
                                }
                                string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(pickDetailInfo.OrderID, pickDetailInfo.OrderLineID, whLoginID);
                                orderDetailDA.UpdateOrderDetailStatus(pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, this.pubParasInfo.UserID, whLoginID);
                                waveDetailDA.UpdateWaveDetailStatusByOrderIDAndBatchFlagIsY(pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, this.pubParasInfo.UserID, whLoginID);
                                OrdersInfo ordersInfo4Status = this.UpdateSalesOrderDetailStatusAndQty(pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                                this.UpdateSalesOrderStatus(ordersInfo4Status.OrderID, whLoginID, this.pubParasInfo);
                                temp = temp + pickDetailID[i] + ",";
                            }
                        }
                    }
                }
                if ((orderIDList != null) && (orderIDList.Count > 0))
                {
                    WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
                    for (i = 0; i < orderIDList.Count; i++)
                    {
                        string orderStatus = orderBll.GetOrderStatus(orderIDList[i], whLoginID, this.pubParasInfo);
                        ordersDA.UpdateOrdersStatus(orderIDList[i], orderStatus, updateBy, whLoginID);
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(orderIDList[i], orderStatus, updateBy, whLoginID);
                        wavebll.UpdateWaveStatusByOrderID(orderIDList[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return ((temp.Length > 0) ? temp.Substring(0, temp.Length - 1) : "");
        }

        public string ConfirmShipped(List<string> pickDetailID, string shippDate, string updateBy)
        {
            int temp = 0;
            List<string> intransitIDs = new List<string>();
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            IntransitDetailBLL intransitDetailBll = new IntransitDetailBLL(this.pubParasInfo);
            IntransitBLL intransitBll = new IntransitBLL(this.pubParasInfo);
            WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
            ReceiptBLL receiptBll = new ReceiptBLL(this.pubParasInfo);
            List<OrderDetailInfo> orderDetailList = new List<OrderDetailInfo>();
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                Hashtable ht = new Hashtable();
                for (int i = 0; i < pickDetailID.Count; i++)
                {
                    SysSettingInfo sysSettinginfo;
                    List<PickDetailInfo> pickDetailInfos4ASN;
                    PickDetailInfo pickDetailInfo = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    OrdersInfo ordersinfo = ordersDA.GetOrdersByID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                    SysSettingInfo sysSetting = sysSettingDA.GetSysSettingByID("AllowChangeActualShipDate", whLoginID, this.pubParasInfo);
                    if (sysSetting != null)
                    {
                        if ((sysSetting.Value == "N") || string.IsNullOrEmpty(shippDate))
                        {
                            sysSettinginfo = sysSettingDA.GetSysSettingByID("ActualShipDateSameAsRequest", whLoginID, this.pubParasInfo);
                            if (sysSettinginfo != null)
                            {
                                if (sysSettinginfo.Value == "Y")
                                {
                                    shippDate = ordersinfo.RequestedShipDate.ToString();
                                }
                                else
                                {
                                    shippDate = DateTime.Now.ToString();
                                }
                            }
                        }
                    }
                    else
                    {
                        sysSettinginfo = sysSettingDA.GetSysSettingByID("ActualShipDateSameAsRequest", whLoginID, this.pubParasInfo);
                        if (sysSettinginfo != null)
                        {
                            if (sysSettinginfo.Value == "Y")
                            {
                                shippDate = ordersinfo.RequestedShipDate.ToString();
                            }
                            else
                            {
                                shippDate = DateTime.Now.ToString();
                            }
                        }
                        else
                        {
                            shippDate = DateTime.Now.ToString();
                        }
                    }
                    SysSettingInfo sysSettingDeliveryTime = sysSettingDA.GetSysSettingByID("DeliveryTimeCheckTheShelfLife", whLoginID, this.pubParasInfo);
                    if ((sysSettingDeliveryTime != null) && (sysSettingDeliveryTime.Value == "Y"))
                    {
                        SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, pickDetailInfo.OwnerID, pickDetailInfo.SkuID, whLoginID);
                        LotAttributeInfo lotInfo = lotAttributeDA.GetLotAttributeByID(dataBase, tran, pickDetailInfo.Lot, whLoginID);
                        if (skuInfo.ShelfLifeIndicator == "Y")
                        {
                            DateTime CS00002;
                            DateTime ShippDateTime = DateTime.Parse(shippDate);
                            if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                            {
                                CS00002 = lotInfo.ExpiryDate;
                                if ((!string.IsNullOrEmpty(CS00002.ToString()) && (lotInfo.ExpiryDate != new DateTime())) && (ShippDateTime.AddDays((double) skuInfo.ShelfLife) > lotInfo.ExpiryDate))
                                {
                                    throw new Exception("出库保质期不满足!");
                                }
                            }
                            else
                            {
                                CS00002 = lotInfo.ProduceDate;
                                if ((!string.IsNullOrEmpty(CS00002.ToString()) && (lotInfo.ProduceDate != new DateTime())) && (lotInfo.ProduceDate.AddDays((double) skuInfo.ShelfLife) > ShippDateTime))
                                {
                                    throw new Exception("出库保质期不满足!");
                                }
                            }
                        }
                    }
                    List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                    OrderDetailInfo orderDetailInfo = null;
                    for (int j = 0; j < orderDetailInfos.Count; j++)
                    {
                        if (orderDetailInfos[j].LineID == pickDetailInfo.OrderLineID)
                        {
                            OrderDetailInfo local1 = orderDetailInfos[j];
                            local1.PickedQty -= pickDetailInfo.Qty;
                            OrderDetailInfo local2 = orderDetailInfos[j];
                            local2.ShippedQty += pickDetailInfo.Qty;
                            orderDetailInfo = orderDetailInfos[j];
                            break;
                        }
                    }
                    pickDetailDa.UpdatePickDetailStatus(dataBase, tran, pickDetailID[i], PickDetailStatus.Shipped, updateBy, whLoginID);
                    InvLotInfo invLotinfo = new InvLotInfo {
                        Lot = pickDetailInfo.Lot,
                        UpdatedBy = updateBy,
                        Qty = pickDetailInfo.Qty
                    };
                    invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.ShippedQty, whLoginID);
                    InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                        Lot = pickDetailInfo.Lot,
                        Loc = pickDetailInfo.ToLoc,
                        LpnID = pickDetailInfo.LpnID,
                        Qty = pickDetailInfo.Qty,
                        UpdatedBy = updateBy
                    };
                    invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.ShippedQty, whLoginID);
                    InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                        Loc = pickDetailInfo.ToLoc,
                        SkuID = pickDetailInfo.SkuID,
                        OwnerID = pickDetailInfo.OwnerID,
                        UpdatedBy = updateBy,
                        Qty = pickDetailInfo.Qty
                    };
                    invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.ShippedQty, whLoginID);
                    LpnInfo lpnInfo = new LpnInfo();
                    if (!string.IsNullOrEmpty(pickDetailInfo.LpnID))
                    {
                        lpnInfo = lpnDA.GetLpnByID(dataBase, tran, pickDetailInfo.LpnID, whLoginID);
                        if (lpnInfo != null)
                        {
                            lpnInfo.Qty -= pickDetailInfo.Qty;
                            lpnInfo.UpdatedBy = this.pubParasInfo.UserID;
                            lpnDA.UpdateLpn(dataBase, tran, lpnInfo, LpnUpdateType.Qty, whLoginID);
                        }
                    }
                    this.InsertConfirmPickedAndShippedTrans(dataBase, tran, pickDetailInfo, "Shipped", shippDate, whLoginID);
                    string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                    orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty, updateBy, OrderDetailUpdateType.ShippedQty, whLoginID);
                    if (!string.IsNullOrEmpty(shippDate))
                    {
                        orderDetailDA.UpdateOrderDetailActualShipDateByOrderID(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), shippDate, updateBy, whLoginID);
                    }
                    string orderStatus = orderBll.GetOrderStatus(orderDetailInfos);
                    ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                    waveDetailDA.UpdateWaveDetailStatusByOrderIDAndBatchFlagIsY(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, this.pubParasInfo.UserID, whLoginID);
                    ordersDA.UpdateOrderActualShipDateByOrderID(dataBase, tran, pickDetailInfo.OrderID, shippDate, updateBy, whLoginID);
                    OrdersInfo ordersInfo4Status = this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty, whLoginID, this.pubParasInfo);
                    this.UpdateSalesOrderStatus(dataBase, tran, ordersInfo4Status.OrderID, whLoginID, this.pubParasInfo);
                    loadDetailDA.UpdateLoadDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                    IntransitDetailInfo intransitDetailInfo = inTransitDetailDA.GetIntransitDetailByOrderID(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), whLoginID);
                    if ((intransitDetailInfo != null) && !string.IsNullOrEmpty(intransitDetailInfo.IntransitID))
                    {
                        if (!intransitIDs.Contains(intransitDetailInfo.IntransitID))
                        {
                            intransitIDs.Add(intransitDetailInfo.IntransitID);
                        }
                        intransitDetailInfo.ShippedQty += pickDetailInfo.Qty;
                        string intransitDetailStatus = intransitDetailBll.GetIntransitDetailStatus(intransitDetailInfo);
                        inTransitDetailDA.UpdateIntransitDetailQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), IntransitUpdateType.ShippedQty, pickDetailInfo.Qty, intransitDetailStatus, updateBy, whLoginID);
                    }
                    waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                    wavebll.UpdateWaveStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID);
                    if (ht.Contains(pickDetailInfo.OrderID))
                    {
                        pickDetailInfos4ASN = ht[pickDetailInfo.OrderID] as List<PickDetailInfo>;
                        if ((pickDetailInfos4ASN != null) && (pickDetailInfos4ASN.Count > 0))
                        {
                            pickDetailInfos4ASN.Add(pickDetailInfo);
                        }
                    }
                    else
                    {
                        pickDetailInfos4ASN = new List<PickDetailInfo> {
                            pickDetailInfo
                        };
                        ht.Add(pickDetailInfo.OrderID, pickDetailInfos4ASN);
                    }
                }
                if ((ht != null) && (ht.Count > 0))
                {
                    this.CreateASNByOrderIDCollection(dataBase, tran, ht, receiptBll, updateBy, whLoginID);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            this.UpdateIntransitStatus(intransitIDs, intransitBll, updateBy, whLoginID);
            return temp.ToString();
        }

        private void CreateASNByOrderIDCollection(DataBase database, DbTransaction tran, Hashtable ht, ReceiptBLL reciptBll, string createdBy, string whLoginID)
        {
            if ((ht != null) && (ht.Count > 0))
            {
                foreach (DictionaryEntry item in ht)
                {
                    OrdersInfo ordersInfo = ordersDA.GetOrdersByID(database, tran, item.Key.ToString(), whLoginID, this.pubParasInfo);
                    if ((ordersInfo != null) && (ordersInfo.Type == OrderTypes.Transfer))
                    {
                        List<PickDetailInfo> pickDetailInfos = item.Value as List<PickDetailInfo>;
                        if ((pickDetailInfos != null) && (pickDetailInfos.Count > 0))
                        {
                            IntransitInfo inTranSitInfo = inTransitDA.GetIntransitByOrderID(database, tran, item.Key.ToString(), whLoginID);
                            ReceiptInfo receiptInfo = this.ChangeOrdersInfo2ReceiptInfo(database, tran, ordersInfo, pickDetailInfos, whLoginID);
                            if (receiptInfo != null)
                            {
                                receiptInfo.CreatedBy = inTranSitInfo.SrcWhDbID.ToString();
                                List<string> dataBaseIDTemp = commonMethod.GetDataBaseID(database, tran, inTranSitInfo.DestWhDbID.ToString());
                                receiptInfo.IsTransfer = "Y";
                                string receiptID = reciptBll.InsertReceipt(database, tran, receiptInfo, dataBaseIDTemp[0]);
                                string tempReceiptID = string.IsNullOrEmpty(inTranSitInfo.ReceiptID) ? receiptID : (inTranSitInfo.ReceiptID + "," + receiptID);
                                inTransitDA.UpdateReceiptIDByIntransitID(database, tran, inTranSitInfo.IntransitID, tempReceiptID, inTranSitInfo.UpdatedBy, whLoginID);
                            }
                        }
                    }
                }
            }
        }

        public string DirectAllocation(string orderID, List<string> orderLineIDS)
        {
            int i;
            string whLoginID = this.dataBaseID[0];
            string where = string.Empty;
            string temp = string.Empty;
            List<OrderDetailInfo> orderDetailInfos = null;
            if ((orderLineIDS != null) && (orderLineIDS.Count > 0))
            {
                where = " AND OD.STATUS IN ('NEW') AND OD.LINE_ID IN ('";
                for (i = 0; i < orderLineIDS.Count; i++)
                {
                    where = where + orderLineIDS[i] + "','";
                }
                where = where.Substring(0, where.Length - 2) + ")";
                orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            }
            else
            {
                where = " AND OD.STATUS IN ('NEW') ";
                orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
            }
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
                Dictionary<string, RotationRuleInfo> rotationRuleObjects = new Dictionary<string, RotationRuleInfo>();
                Dictionary<string, InvLotInfo> invLotObjects = new Dictionary<string, InvLotInfo>();
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    for (i = 0; i < orderDetailInfos.Count; i++)
                    {
                        List<InventoryInfo> inventoryInfos = new List<InventoryInfo>();
                        decimal orderQty = orderDetailInfos[i].OriginalQty - orderDetailInfos[i].AllocatedQty;
                        RotationRuleInfo rotationRuleInfo = null;
                        if (!rotationRuleObjects.ContainsKey(orderDetailInfos[i].SkuRotation))
                        {
                            rotationRuleInfo = rotataionRuleDA.GetRotationRuleByID(dataBase, tran, orderDetailInfos[i].SkuRotation, whLoginID);
                            if (rotationRuleInfo == null)
                            {
                                throw new Exception("发货订单行" + orderDetailInfos[i].SkuID + "没有指定周转规则,导入失败");
                            }
                            rotationRuleInfo.RotationRuleDetailInfo = rotataionRuleDetailDA.GetRotationRuleDetailListByID(dataBase, tran, orderDetailInfos[i].SkuRotation, whLoginID);
                            rotationRuleObjects.Add(rotationRuleInfo.RotationRuleID, rotationRuleInfo);
                        }
                        else
                        {
                            rotationRuleObjects.TryGetValue(orderDetailInfos[i].SkuRotation, out rotationRuleInfo);
                        }
                        string orderBy = this.OrganizeRotationRule(rotationRuleInfo);
                        LotAttributeInfo lotAttribute = new LotAttributeInfo {
                            OwnerID = orderDetailInfos[i].OwnerID,
                            SkuID = orderDetailInfos[i].SkuID,
                            LotAttr01 = orderDetailInfos[i].LotAttr01,
                            LotAttr02 = orderDetailInfos[i].LotAttr02,
                            LotAttr03 = orderDetailInfos[i].LotAttr03,
                            LotAttr04 = orderDetailInfos[i].LotAttr04,
                            LotAttr05 = orderDetailInfos[i].LotAttr05,
                            LotAttr06 = orderDetailInfos[i].LotAttr06,
                            LotAttr07 = orderDetailInfos[i].LotAttr07,
                            LotAttr08 = orderDetailInfos[i].LotAttr08,
                            LotAttr09 = orderDetailInfos[i].LotAttr09,
                            LotAttr10 = orderDetailInfos[i].LotAttr10,
                            ProduceDate = orderDetailInfos[i].ProduceDate,
                            ExpiryDate = orderDetailInfos[i].ExpiryDate,
                            ReceiptDate = orderDetailInfos[i].ReceiptDate,
                            ExternalLot = orderDetailInfos[i].ExternalLot,
                            VendorID = orderDetailInfos[i].VendorID
                        };
                        List<InventoryInfo> inventoryInfos2 = inventoryMgtDA.GetInventoryInfoByLotAttribute(dataBase, tran, lotAttribute, "", orderDetailInfos[i].LpnID, orderBy, whLoginID);
                        if ((inventoryInfos2 != null) && (inventoryInfos2.Count > 0))
                        {
                            Dictionary<string, List<InventoryInfo>> inventoryInfoGroupByLot = new Dictionary<string, List<InventoryInfo>>();
                            Dictionary<string, decimal> originalLotPreAllocateQty = new Dictionary<string, decimal>();
                            int j = 0;
                            while (j < inventoryInfos2.Count)
                            {
                                if (((inventoryInfos2[j].Status.ToUpper() == "OK") && (inventoryInfos2[j].AvailableQty > 0M)) && !string.IsNullOrEmpty(inventoryInfos2[j].LpnID))
                                {
                                    decimal availableQty = inventoryInfos2[j].AvailableQty;
                                    InvLotInfo invLotInfo = null;
                                    if (invLotObjects.ContainsKey(inventoryInfos2[j].Lot))
                                    {
                                        invLotObjects.TryGetValue(inventoryInfos2[j].Lot, out invLotInfo);
                                        if (!originalLotPreAllocateQty.ContainsKey(inventoryInfos2[j].Lot))
                                        {
                                            originalLotPreAllocateQty.Add(inventoryInfos2[j].Lot, invLotInfo.PreallocatedQty);
                                        }
                                    }
                                    else
                                    {
                                        invLotInfo = invLotDA.GetInvLotByID(dataBase, tran, inventoryInfos2[j].Lot, whLoginID);
                                        invLotObjects.Add(inventoryInfos2[j].Lot, invLotInfo);
                                        if (!originalLotPreAllocateQty.ContainsKey(inventoryInfos2[j].Lot))
                                        {
                                            originalLotPreAllocateQty.Add(inventoryInfos2[j].Lot, invLotInfo.PreallocatedQty);
                                        }
                                    }
                                    decimal lotAvailableQty = (((invLotInfo.Qty - invLotInfo.PreallocatedQty) - invLotInfo.AllocatedQty) - invLotInfo.PickedQty) - invLotInfo.OnholdQty;
                                    if (availableQty > lotAvailableQty)
                                    {
                                        availableQty = lotAvailableQty;
                                        inventoryInfos2[j].AvailableQty = availableQty;
                                        invLotInfo.PreallocatedQty += availableQty;
                                    }
                                    else if (availableQty <= lotAvailableQty)
                                    {
                                        invLotInfo.PreallocatedQty += availableQty;
                                    }
                                    invLotObjects[inventoryInfos2[j].Lot] = invLotInfo;
                                    List<InventoryInfo> tmpInventoryInfo = null;
                                    if (inventoryInfoGroupByLot.ContainsKey(inventoryInfos2[j].Lot))
                                    {
                                        tmpInventoryInfo = inventoryInfoGroupByLot[inventoryInfos2[j].Lot];
                                        tmpInventoryInfo.Add(inventoryInfos2[j]);
                                        inventoryInfoGroupByLot[inventoryInfos2[j].Lot] = tmpInventoryInfo;
                                    }
                                    else
                                    {
                                        tmpInventoryInfo = new List<InventoryInfo> {
                                            inventoryInfos2[j]
                                        };
                                        inventoryInfoGroupByLot.Add(inventoryInfos2[j].Lot, tmpInventoryInfo);
                                    }
                                }
                                j++;
                            }
                            if ((originalLotPreAllocateQty != null) && (originalLotPreAllocateQty.Count > 0))
                            {
                                foreach (KeyValuePair<string, decimal> item in originalLotPreAllocateQty)
                                {
                                    invLotObjects[item.Key].PreallocatedQty = item.Value;
                                }
                            }
                            foreach (KeyValuePair<string, List<InventoryInfo>> item in inventoryInfoGroupByLot)
                            {
                                bool isOver = false;
                                if (orderQty <= 0M)
                                {
                                    break;
                                }
                                List<InventoryInfo> inventoryInfos3 = item.Value;
                                inventoryInfos3.Sort((i1, i2) => Comparer<decimal>.Default.Compare(i2.AvailableQty, i1.AvailableQty));
                                for (j = 0; j < inventoryInfos3.Count; j++)
                                {
                                    if (isOver)
                                    {
                                        break;
                                    }
                                    if (inventoryInfos3[j].AvailableQty < orderQty)
                                    {
                                        decimal tmpInvAvailableQty = 0M;
                                        bool isRemainFit = false;
                                        int notMoreFlag = j;
                                        int k = notMoreFlag;
                                        while (k < inventoryInfos3.Count)
                                        {
                                            tmpInvAvailableQty += inventoryInfos3[k].AvailableQty;
                                            if (tmpInvAvailableQty >= orderQty)
                                            {
                                                isRemainFit = true;
                                                break;
                                            }
                                            k++;
                                        }
                                        if (isRemainFit)
                                        {
                                            int m;
                                            List<InventoryInfo> inventoryInfos4 = new List<InventoryInfo>();
                                            decimal orderQty2 = orderQty;
                                            decimal totalOrderQty2 = 0M;
                                            k = notMoreFlag;
                                            while (k < inventoryInfos3.Count)
                                            {
                                                if (orderQty2 <= 0M)
                                                {
                                                    break;
                                                }
                                                if (inventoryInfos3[k].AvailableQty <= orderQty2)
                                                {
                                                    inventoryInfos4.Add(inventoryInfos3[k]);
                                                    orderQty2 -= inventoryInfos3[k].AvailableQty;
                                                    totalOrderQty2 += inventoryInfos3[k].AvailableQty;
                                                }
                                                else if (k != (inventoryInfos3.Count - 1))
                                                {
                                                    decimal remainNotFitQty = 0M;
                                                    for (int remainNotFitFlag = k + 1; remainNotFitFlag < inventoryInfos3.Count; remainNotFitFlag++)
                                                    {
                                                        remainNotFitQty += inventoryInfos3[remainNotFitFlag].AvailableQty;
                                                    }
                                                    if (remainNotFitQty < orderQty2)
                                                    {
                                                        inventoryInfos4.Add(inventoryInfos3[k]);
                                                        orderQty2 -= inventoryInfos3[k].AvailableQty;
                                                        totalOrderQty2 += inventoryInfos3[k].AvailableQty;
                                                    }
                                                }
                                                else
                                                {
                                                    inventoryInfos4.Add(inventoryInfos3[k]);
                                                    orderQty2 -= inventoryInfos3[k].AvailableQty;
                                                    totalOrderQty2 += inventoryInfos3[k].AvailableQty;
                                                }
                                                k++;
                                            }
                                            if (inventoryInfos4.Count <= 0)
                                            {
                                                continue;
                                            }
                                            if (j > 0)
                                            {
                                                bool isFit = false;
                                                m = j - 1;
                                                while (m >= 0)
                                                {
                                                    if (Math.Abs((decimal) (inventoryInfos3[m].AvailableQty - orderQty)) <= Math.Abs((decimal) (totalOrderQty2 - orderQty)))
                                                    {
                                                        inventoryInfos.Add(inventoryInfos3[m]);
                                                        orderQty -= inventoryInfos3[m].AvailableQty;
                                                        isOver = true;
                                                        isFit = true;
                                                        break;
                                                    }
                                                    m--;
                                                }
                                                if (!isFit)
                                                {
                                                    m = 0;
                                                    while (m < inventoryInfos4.Count)
                                                    {
                                                        inventoryInfos.Add(inventoryInfos4[m]);
                                                        orderQty -= inventoryInfos4[m].AvailableQty;
                                                        m++;
                                                    }
                                                    isOver = true;
                                                }
                                                break;
                                            }
                                            for (m = 0; m < inventoryInfos4.Count; m++)
                                            {
                                                inventoryInfos.Add(inventoryInfos4[m]);
                                                orderQty -= inventoryInfos4[m].AvailableQty;
                                            }
                                            isOver = true;
                                            break;
                                        }
                                        if (notMoreFlag > 0)
                                        {
                                            inventoryInfos.Add(inventoryInfos3[notMoreFlag - 1]);
                                            orderQty -= inventoryInfos3[notMoreFlag - 1].AvailableQty;
                                            isOver = true;
                                        }
                                        else
                                        {
                                            for (k = notMoreFlag; k < inventoryInfos3.Count; k++)
                                            {
                                                inventoryInfos.Add(inventoryInfos3[k]);
                                                orderQty -= inventoryInfos3[k].AvailableQty;
                                            }
                                            isOver = true;
                                        }
                                        break;
                                    }
                                    if (inventoryInfos3[j].AvailableQty == orderQty)
                                    {
                                        inventoryInfos.Add(inventoryInfos3[j]);
                                        orderQty -= inventoryInfos3[j].AvailableQty;
                                        isOver = true;
                                        break;
                                    }
                                    if (inventoryInfos3[inventoryInfos3.Count - 1].AvailableQty > orderQty)
                                    {
                                        inventoryInfos.Add(inventoryInfos3[inventoryInfos3.Count - 1]);
                                        orderQty -= inventoryInfos3[j].AvailableQty;
                                        isOver = true;
                                        break;
                                    }
                                }
                            }
                            if ((inventoryInfos != null) && (inventoryInfos.Count > 0))
                            {
                                decimal totalAllocatedQty2 = 0M;
                                for (int n = 0; n < inventoryInfos.Count; n++)
                                {
                                    PickDetailInfo pickDetailInfo;
                                    pickDetailInfo = new PickDetailInfo();
                                    pickDetailInfo.PickDetailID = commonMethod.GenNextNumStr(dataBase, tran, "PICK_DETAIL", whLoginID);
                                    pickDetailInfo.Lot = inventoryInfos[n].Lot;
                                    pickDetailInfo.Loc = inventoryInfos[n].Loc;
                                    pickDetailInfo.LpnID = inventoryInfos[n].LpnID;
                                    pickDetailInfo.ToLoc = this.GetDetailPickToLocByFromLoc(dataBase, tran, pickDetailInfo.Loc, whLoginID);
                                    pickDetailInfo.OrderID = orderDetailInfos[i].OrderID;
                                    pickDetailInfo.OrderLineID = orderDetailInfos[i].LineID;
                                    pickDetailInfo.PreallocatePickDetailID = "";
                                    pickDetailInfo.OwnerID = orderDetailInfos[i].OwnerID;
                                    pickDetailInfo.SkuID = orderDetailInfos[i].SkuID;
                                    pickDetailInfo.PackID = orderDetailInfos[i].PackID;
                                    PackInfo packInfo = packDA.GetPackByID(dataBase, tran, orderDetailInfos[i].PackID, whLoginID);
                                    pickDetailInfo.Qty = inventoryInfos[n].AvailableQty;
                                    pickDetailInfo.Status = PickDetailStatus.New;
                                    pickDetailInfo.UomID = packInfo.PackUom1;
                                    pickDetailInfo.CaseID = "";
                                    pickDetailInfo.AltSkuID = "";
                                    pickDetailInfo.DropID = "";
                                    pickDetailInfo.UomQty = inventoryInfos[n].AvailableQty;
                                    pickDetailInfo.MovedQty = 0M;
                                    pickDetailInfo.UpdateSource = "";
                                    pickDetailInfo.PickMethod = "";
                                    pickDetailInfo.WaveID = "";
                                    pickDetailInfo.FreightCharges = 0.0;
                                    pickDetailInfo.IsClosed = "";
                                    pickDetailInfo.QcStatus = "";
                                    pickDetailInfo.EffectiveDate = DateTime.Now;
                                    pickDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                                    pickDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                                    temp = temp + pickDetailDa.InsertPickDetail(dataBase, tran, pickDetailInfo, whLoginID) + ",";
                                    InvLotInfo invLotinfo = new InvLotInfo {
                                        Lot = inventoryInfos[n].Lot,
                                        UpdatedBy = this.pubParasInfo.UserID,
                                        AllocatedQty = inventoryInfos[n].AvailableQty,
                                        AllocatedGrossWgt = 0.0,
                                        AllocatedNetWgt = 0.0
                                    };
                                    invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.AllocatedQtyWgtOnly, whLoginID);
                                    InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                        Lot = inventoryInfos[n].Lot,
                                        Loc = inventoryInfos[n].Loc,
                                        LpnID = inventoryInfos[n].LpnID,
                                        AllocatedQty = inventoryInfos[n].AvailableQty,
                                        UpdatedBy = this.pubParasInfo.UserID
                                    };
                                    invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.AllocatedQty, whLoginID);
                                    InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                                        Loc = inventoryInfos[n].Loc,
                                        SkuID = inventoryInfos[n].SkuID,
                                        OwnerID = inventoryInfos[n].OwnerID,
                                        UpdatedBy = this.pubParasInfo.UserID,
                                        AllocatedQty = inventoryInfos[n].AvailableQty
                                    };
                                    invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.AllocatedQty, whLoginID);
                                    InvLotInfo local1 = invLotObjects[pickDetailInfo.Lot];
                                    local1.AllocatedQty += pickDetailInfo.Qty;
                                    totalAllocatedQty2 += inventoryInfos[n].AvailableQty;
                                }
                                OrderDetailInfo local2 = orderDetailInfos[i];
                                local2.AllocatedQty += totalAllocatedQty2;
                                string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfos[i]);
                                orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, orderDetailInfos[i].OrderID, orderDetailInfos[i].LineID.ToString(), orderDetailStatus, totalAllocatedQty2, this.pubParasInfo.UserID, OrderDetailUpdateType.AllocatedQtyOnly, whLoginID);
                                this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfos[i].OrderID, orderDetailInfos[i].LineID.ToString(), OrderStatus.Allocated, 0M, whLoginID, this.pubParasInfo);
                            }
                        }
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
                string orderStatus = orderBll.GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, this.pubParasInfo.UserID, whLoginID);
                new WaveBLL(this.pubParasInfo).UpdateWaveStatusByOrderID(orderID);
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string EncaseNesting(string strFromContainerID, string strToContainerID)
        {
            string ShipmentContainer = string.Empty;
            try
            {
                if (shipmentContainerDA.EncaseNesting(strFromContainerID, strToContainerID, this.dataBaseID[0]) <= 0)
                {
                    return ShipmentContainer;
                }
                string strtype = "嵌套";
                if (string.IsNullOrEmpty(strToContainerID))
                {
                    strtype = "清除";
                }
                ShipmentContainer = "容器" + strFromContainerID + strtype + "成功！";
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return ShipmentContainer;
        }

        public float ExchangeAllocateStratetyUom2PackFactor(PackInfo packInfo, string strategy)
        {
            float packFactor = 0f;
            string CS40001 = strategy;
            if (CS40001 == null)
            {
                return packFactor;
            }
            if (!(CS40001 == "10"))
            {
                if (CS40001 != "20")
                {
                    if (CS40001 == "30")
                    {
                        return packInfo.InnerPack;
                    }
                    if (CS40001 == "40")
                    {
                        return packInfo.OtherUnit1;
                    }
                    if (CS40001 == "50")
                    {
                        return packInfo.OtherUnit2;
                    }
                    if (CS40001 != "60")
                    {
                        return packFactor;
                    }
                    return packInfo.Qty;
                }
            }
            else
            {
                return packInfo.Pallet;
            }
            return packInfo.CaseCnt;
        }

        public string ExchangeAllocateStratetyUom2PackUom(PackInfo packInfo, string strategy)
        {
            string packUom = string.Empty;
            string CS40001 = strategy;
            if (CS40001 == null)
            {
                return packUom;
            }
            if (!(CS40001 == "10"))
            {
                if (CS40001 != "20")
                {
                    if (CS40001 == "30")
                    {
                        return packInfo.PackUom2;
                    }
                    if (CS40001 == "40")
                    {
                        return packInfo.PackUom8;
                    }
                    if (CS40001 == "50")
                    {
                        return packInfo.PackUom9;
                    }
                    if (CS40001 != "60")
                    {
                        return packUom;
                    }
                    return packInfo.PackUom1;
                }
            }
            else
            {
                return packInfo.PackUom4;
            }
            return packInfo.PackUom3;
        }

        public string ExecuteExploding(List<string> orderIDs, List<string> lineIDs)
        {
            string returnValue = string.Empty;
            string whLoginID = this.dataBaseID[0];
            decimal dQty = 0M;
            SysSettingInfo sysSettingInfo = sysSettingDA.GetSysSettingByID("CompleteExplode", whLoginID, this.pubParasInfo);
            for (int i = 0; lineIDs.Count > i; i++)
            {
                List<string> SkuName = new List<string>();
                OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(orderIDs[0], lineIDs[i], whLoginID, this.pubParasInfo);
                dQty = orderDetailInfo.OriginalQty;
                SkuName.Add(orderDetailInfo.SkuID);
                BomInfo bomInfo = bomDA.GetBomByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                if (bomInfo != null)
                {
                    bomInfo.BomDetailInfo = bomDetailDA.GetBomDetailListByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                    if (bomInfo.BomDetailInfo.Count > 0)
                    {
                        DataBase dataBase = new DataBase();
                        DbConnection conn = dataBase.connection;
                        conn.Open();
                        DbTransaction tran = conn.BeginTransaction();
                        int LineID = orderDetailDA.GetMaxOrderDetailLineID(dataBase, tran, orderIDs[0], whLoginID);
                        orderDetailDA.DeleteOrderDetail(dataBase, tran, new List<string> { orderDetailInfo.OrderID }, new List<string> { orderDetailInfo.LineID.ToString() }, this.dataBaseID);
                        try
                        {
                            bool btran = true;
                            foreach (BomDetailInfo info in bomInfo.BomDetailInfo)
                            {
                                SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, info.OwnerID, info.SkuID, whLoginID);
                                if (skuInfo != null)
                                {
                                    PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuInfo.PackID, whLoginID);
                                    orderDetailInfo.LineID = LineID + 10;
                                    orderDetailInfo.SkuID = info.ComponentSkuID;
                                    orderDetailInfo.OriginalQty = dQty * info.Qty;
                                    orderDetailInfo.PackID = skuInfo.PackID;
                                    orderDetailInfo.UomID = packInfo.PackUom1;
                                    orderDetailDA.InsertOrderDetail(dataBase, tran, orderDetailInfo, whLoginID);
                                    if (((sysSettingInfo != null) && (sysSettingInfo.Value == "Y")) && !this.AutomaticExecuteExploaing(dataBase, tran, orderDetailInfo, SkuName))
                                    {
                                        btran = false;
                                        returnValue = returnValue + orderDetailInfo.SkuID + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_025", this.pubParasInfo.UserLanguage);
                                        break;
                                    }
                                }
                                LineID = orderDetailInfo.LineID;
                            }
                            if (btran)
                            {
                                tran.Commit();
                            }
                            else
                            {
                                tran.Rollback();
                            }
                        }
                        catch (Exception)
                        {
                            tran.Rollback();
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                    else
                    {
                        returnValue = returnValue + orderDetailInfo.SkuID + ";";
                    }
                }
                else
                {
                    returnValue = returnValue + orderDetailInfo.SkuID + ";";
                }
            }
            return returnValue;
        }

        public string GetDetailPickToLocByFromLoc(DataBase database, DbTransaction tran, string fromLoc, string whLoginID)
        {
            string pickToLoc = "PICKTO";
            LocationInfo loc = locationDA.GetLocationByID(database, tran, fromLoc, whLoginID, this.pubParasInfo);
            if (loc != null)
            {
                ZoneInfo zone = zoneDA.GetZoneByID(database, tran, loc.ZoneID, whLoginID);
                if (zone == null)
                {
                    return pickToLoc;
                }
                if (!string.IsNullOrEmpty(zone.PickToLoc))
                {
                    pickToLoc = zone.PickToLoc;
                }
            }
            return pickToLoc;
        }

        private List<InvLotInfo> GetInvLotByLotAttribute(DataBase database, DbTransaction tran, OrderDetailInfo orderDetailInfo, string whLoginID)
        {
            LotAttributeInfo lotAttribute = new LotAttributeInfo {
                OwnerID = orderDetailInfo.OwnerID,
                SkuID = orderDetailInfo.SkuID,
                LotAttr01 = orderDetailInfo.LotAttr01,
                LotAttr02 = orderDetailInfo.LotAttr02,
                LotAttr03 = orderDetailInfo.LotAttr03,
                LotAttr04 = orderDetailInfo.LotAttr04,
                LotAttr05 = orderDetailInfo.LotAttr05,
                LotAttr06 = orderDetailInfo.LotAttr06,
                LotAttr07 = orderDetailInfo.LotAttr07,
                LotAttr08 = orderDetailInfo.LotAttr08,
                LotAttr09 = orderDetailInfo.LotAttr09,
                LotAttr10 = orderDetailInfo.LotAttr10,
                ProduceDate = orderDetailInfo.ProduceDate,
                ExpiryDate = orderDetailInfo.ExpiryDate,
                ReceiptDate = orderDetailInfo.ReceiptDate,
                ExternalLot = orderDetailInfo.ExternalLot,
                VendorID = orderDetailInfo.VendorID
            };
            string rotationRule = orderDetailInfo.SkuRotation;
            string sqlOrderBy = this.OrganizeRotationRule(database, tran, rotationRule, whLoginID);
            return lotAttributeDA.GetLotIDByLotAttribute4PreAllocate(database, tran, lotAttribute, sqlOrderBy, whLoginID);
        }

        private List<InvLotInfo> GetInvLotByLotAttribute4ManualAllocate(LotAttributeInfo lotAttribute, string whLoginID)
        {
            string sqlOrderBy = "";
            return lotAttributeDA.GetLotIDByLotAttribute4PreAllocate(lotAttribute, sqlOrderBy, whLoginID);
        }

        public List<string> GetUnPrintShippingPickDetailIDByOrderID(string orderID)
        {
            List<string> pickDetailIDs = new List<string>();
            DataSet ds = pickDetailDa.GetUnPrintShippingPickDetailIDByOrderID(orderID, this.dataBaseID[0]);
            if (((ds != null) && (ds.Tables.Count > 0)) && (ds.Tables[0].Rows.Count > 0))
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    pickDetailIDs.Add(row["PICK_DETAIL_ID"].ToString());
                }
            }
            return pickDetailIDs;
        }

        private string InsertConfirmPickedAndShippedTrans(PickDetailInfo pickDetailInfo, string confirmType, string shippDate, string whLoginID)
        {
            InvTransInfo invTransInfo = new InvTransInfo {
                TransID = commonMethod.GenNextNumStr("INV_TRANS", whLoginID),
                OwnerID = pickDetailInfo.OwnerID,
                SkuID = pickDetailInfo.SkuID,
                Lot = pickDetailInfo.Lot,
                DocID = pickDetailInfo.PickDetailID,
                DocLineID = 0,
                Qty = pickDetailInfo.Qty
            };
            if (confirmType.ToUpper() == "PICKED")
            {
                invTransInfo.FromLoc = pickDetailInfo.Loc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = pickDetailInfo.ToLoc;
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Movement;
                invTransInfo.SourceTransType = TransSourceType.Picking;
                invTransInfo.Status = TransStatus.OK;
            }
            else if (confirmType.ToUpper() == "SHIPPED")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Shipment;
                invTransInfo.SourceTransType = TransSourceType.PickingUpdate;
                invTransInfo.Status = TransStatus.OK;
                if (!string.IsNullOrEmpty(shippDate))
                {
                    invTransInfo.TransDate = Convert.ToDateTime(shippDate);
                }
                invTransInfo.Qty = pickDetailInfo.Qty * -1M;
            }
            else if (confirmType.ToUpper() == "SHIPMENTREVERAL")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Adjustment;
                invTransInfo.SourceTransType = TransSourceType.ShipmentReversal;
                invTransInfo.Status = TransStatus.OK;
            }
            else if (confirmType.ToUpper() == "OT")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Shipment;
                invTransInfo.SourceTransType = TransSourceType.ShipmentReversal;
                invTransInfo.Status = TransStatus.OK;
            }
            LotAttributeInfo lotInfo = lotAttributeDA.GetLotAttributeByID(pickDetailInfo.Lot, whLoginID);
            if (lotInfo != null)
            {
                invTransInfo.LotAttr01 = lotInfo.LotAttr01;
                invTransInfo.LotAttr02 = lotInfo.LotAttr02;
                invTransInfo.LotAttr03 = lotInfo.LotAttr03;
                invTransInfo.LotAttr04 = lotInfo.LotAttr04;
                invTransInfo.LotAttr05 = lotInfo.LotAttr05;
                invTransInfo.LotAttr06 = lotInfo.LotAttr06;
                invTransInfo.LotAttr07 = lotInfo.LotAttr07;
                invTransInfo.LotAttr08 = lotInfo.LotAttr08;
                invTransInfo.LotAttr09 = lotInfo.LotAttr09;
                invTransInfo.LotAttr10 = lotInfo.LotAttr10;
                invTransInfo.ProduceDate = lotInfo.ProduceDate;
                invTransInfo.ExpiryDate = lotInfo.ExpiryDate;
                invTransInfo.ReceiptDate = lotInfo.ReceiptDate;
                invTransInfo.ExternalLot = lotInfo.ExternalLot;
                invTransInfo.VendorID = lotInfo.VendorID;
            }
            invTransInfo.CaseCnt = 0M;
            invTransInfo.InnerPack = 0M;
            invTransInfo.Pallet = 0M;
            invTransInfo.Cube = 0.0;
            invTransInfo.GrossWgt = 0.0;
            invTransInfo.NetWgt = 0.0;
            invTransInfo.OtherUnit1 = 0.0;
            invTransInfo.OtherUnit2 = 0.0;
            invTransInfo.PackID = pickDetailInfo.PackID;
            invTransInfo.UomID = pickDetailInfo.UomID;
            invTransInfo.UomCalc = Convert.ToInt32(pickDetailInfo.Qty);
            invTransInfo.UomQty = pickDetailInfo.Qty;
            InvLotInfo invLotInfo = invLotDA.GetInvLotByID(pickDetailInfo.Lot, whLoginID);
            if (invLotInfo != null)
            {
                invTransInfo.UnitPrice = invLotInfo.UnitPrice;
                invTransInfo.Cube = invLotInfo.Cube;
                invTransInfo.GrossWgt = invLotInfo.GrossWgt;
                invTransInfo.NetWgt = invLotInfo.NetWgt;
            }
            invTransInfo.CreatedBy = pickDetailInfo.UpdatedBy;
            invTransInfo.UpdatedBy = pickDetailInfo.UpdatedBy;
            invTransDA.InsertInvTrans(invTransInfo, whLoginID);
            return invTransInfo.TransID;
        }

        private string InsertConfirmPickedAndShippedTrans(DataBase database, DbTransaction tran, PickDetailInfo pickDetailInfo, string confirmType, string shippDate, string whLoginID)
        {
            InvTransInfo invTransInfo = new InvTransInfo {
                TransID = commonMethod.GenNextNumStr(database, tran, "INV_TRANS", whLoginID),
                OwnerID = pickDetailInfo.OwnerID,
                SkuID = pickDetailInfo.SkuID,
                Lot = pickDetailInfo.Lot,
                DocID = pickDetailInfo.PickDetailID,
                DocLineID = 0,
                Qty = pickDetailInfo.Qty
            };
            if (confirmType.ToUpper() == "PICKED")
            {
                invTransInfo.FromLoc = pickDetailInfo.Loc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = pickDetailInfo.ToLoc;
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Movement;
                invTransInfo.SourceTransType = TransSourceType.Picking;
                invTransInfo.Status = TransStatus.OK;
            }
            else if (confirmType.ToUpper() == "SHIPPED")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Shipment;
                invTransInfo.SourceTransType = TransSourceType.PickingUpdate;
                invTransInfo.Status = TransStatus.OK;
                if (!string.IsNullOrEmpty(shippDate))
                {
                    invTransInfo.TransDate = Convert.ToDateTime(shippDate);
                }
                invTransInfo.Qty = pickDetailInfo.Qty * -1M;
            }
            else if (confirmType.ToUpper() == "SHIPMENTREVERAL")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Adjustment;
                invTransInfo.SourceTransType = TransSourceType.ShipmentReversal;
                invTransInfo.Status = TransStatus.OK;
            }
            else if (confirmType.ToUpper() == "OT")
            {
                invTransInfo.FromLoc = pickDetailInfo.ToLoc;
                invTransInfo.FromLpnID = pickDetailInfo.LpnID;
                invTransInfo.ToLoc = "";
                invTransInfo.ToLpnID = pickDetailInfo.LpnID;
                invTransInfo.TransType = TransType.Shipment;
                invTransInfo.SourceTransType = TransSourceType.ShipmentReversal;
                invTransInfo.Status = TransStatus.OK;
            }
            LotAttributeInfo lotInfo = lotAttributeDA.GetLotAttributeByID(database, tran, pickDetailInfo.Lot, whLoginID);
            if (lotInfo != null)
            {
                invTransInfo.LotAttr01 = lotInfo.LotAttr01;
                invTransInfo.LotAttr02 = lotInfo.LotAttr02;
                invTransInfo.LotAttr03 = lotInfo.LotAttr03;
                invTransInfo.LotAttr04 = lotInfo.LotAttr04;
                invTransInfo.LotAttr05 = lotInfo.LotAttr05;
                invTransInfo.LotAttr06 = lotInfo.LotAttr06;
                invTransInfo.LotAttr07 = lotInfo.LotAttr07;
                invTransInfo.LotAttr08 = lotInfo.LotAttr08;
                invTransInfo.LotAttr09 = lotInfo.LotAttr09;
                invTransInfo.LotAttr10 = lotInfo.LotAttr10;
                invTransInfo.ProduceDate = lotInfo.ProduceDate;
                invTransInfo.ExpiryDate = lotInfo.ExpiryDate;
                invTransInfo.ReceiptDate = lotInfo.ReceiptDate;
                invTransInfo.ExternalLot = lotInfo.ExternalLot;
                invTransInfo.VendorID = lotInfo.VendorID;
            }
            invTransInfo.CaseCnt = 0M;
            invTransInfo.InnerPack = 0M;
            invTransInfo.Pallet = 0M;
            invTransInfo.Cube = 0.0;
            invTransInfo.GrossWgt = 0.0;
            invTransInfo.NetWgt = 0.0;
            invTransInfo.OtherUnit1 = 0.0;
            invTransInfo.OtherUnit2 = 0.0;
            invTransInfo.PackID = pickDetailInfo.PackID;
            invTransInfo.UomID = pickDetailInfo.UomID;
            invTransInfo.UomCalc = Convert.ToInt32(pickDetailInfo.Qty);
            invTransInfo.UomQty = pickDetailInfo.Qty;
            InvLotInfo invLotInfo = invLotDA.GetInvLotByID(database, tran, pickDetailInfo.Lot, whLoginID);
            if (invLotInfo != null)
            {
                invTransInfo.UnitPrice = invLotInfo.UnitPrice;
                invTransInfo.Cube = invLotInfo.Cube;
                invTransInfo.GrossWgt = invLotInfo.GrossWgt;
                invTransInfo.NetWgt = invLotInfo.NetWgt;
            }
            invTransInfo.CreatedBy = pickDetailInfo.UpdatedBy;
            invTransInfo.UpdatedBy = pickDetailInfo.UpdatedBy;
            invTransDA.InsertInvTrans(database, tran, invTransInfo, whLoginID);
            return invTransInfo.TransID;
        }

        private int InsertPreallocatePickDetailByOrderDetailandInvLot(DataBase database, DbTransaction tran, OrderDetailInfo orderDetailInfo, InvLotInfo invLotInfo, decimal deductInvLotPreAllocateQty, string preAllocateUom, decimal preAllocateUomQty, string updatedBy, string whLoginID)
        {
            PreallocatePickDetailInfo preallocatePickDetailInfo = new PreallocatePickDetailInfo {
                PreallocatePickDetailID = commonMethod.GenNextNumStr(database, tran, "PREALLOCATE_PICK_DETAIL", whLoginID),
                OrderID = orderDetailInfo.OrderID,
                OrderLineID = orderDetailInfo.LineID,
                OwnerID = orderDetailInfo.OwnerID,
                SkuID = orderDetailInfo.SkuID,
                Lot = invLotInfo.Lot,
                UomID = preAllocateUom,
                UomQty = preAllocateUomQty,
                Qty = deductInvLotPreAllocateQty,
                PackID = orderDetailInfo.PackID,
                WaveID = "",
                PreallocateRuleID = orderDetailInfo.PreallocateRuleID,
                PreallocatePickCode = "",
                DoCartonize = "",
                PickMethod = "",
                RunID = "",
                EffectiveDate = DateTime.Now,
                CreatedBy = updatedBy,
                UpdatedBy = updatedBy
            };
            return preAllocatePickDetailDA.InsertPreallocatePickDetail(database, tran, preallocatePickDetailInfo, whLoginID);
        }

        private void InsertRevertPickTasks(DataBase dataBase, DbTransaction tran, PickDetailInfo pickDetailInfo, string updateBy, string whLoginID)
        {
            TaskDetailInfo taskDetailEntity = new TaskDetailInfo {
                TaskDetailID = commonMethod.GenNextNumStr("TASK_DETAIL", whLoginID),
                TaskType = TaskType.MV,
                OwnerID = pickDetailInfo.OwnerID,
                SkuID = pickDetailInfo.SkuID,
                Lot = pickDetailInfo.Lot,
                UomID = pickDetailInfo.UomID,
                UomQty = pickDetailInfo.UomQty,
                Qty = pickDetailInfo.Qty,
                FromLoc = pickDetailInfo.ToLoc,
                LogicalFromLoc = pickDetailInfo.ToLoc,
                FromLpnID = pickDetailInfo.LpnID,
                ToLoc = pickDetailInfo.Loc,
                LogicalToLoc = pickDetailInfo.Loc,
                ToLpnID = pickDetailInfo.LpnID,
                CaseID = pickDetailInfo.CaseID,
                PickMethod = pickDetailInfo.PickMethod,
                Status = TaskStatus.Pending,
                StatusMsg = "",
                Priority = TaskPriority.five,
                SourcePriority = "",
                HoldID = "",
                UserID = "",
                UserPosition = "",
                UserIdOverride = "",
                StartTime = DateTime.Now,
                EndTime = DateTime.Now,
                SourceType = "",
                DocID = pickDetailInfo.OrderID,
                DocLineID = pickDetailInfo.OrderLineID,
                PickDetailID = pickDetailInfo.PickDetailID,
                OrderID = pickDetailInfo.OrderID,
                OrderLineID = pickDetailInfo.OrderLineID,
                ListID = "",
                WaveID = "",
                ReasonID = "",
                Message01 = "",
                Message02 = "",
                Message03 = "",
                FinalToLoc = "",
                FromTransID = "",
                CreatedBy = updateBy,
                UpdatedBy = updateBy
            };
            taskDetailDa.InsertTaskDetail(dataBase, tran, taskDetailEntity, whLoginID);
        }

        private string ManipulatingExecuteExploaing(List<string> orderIDs, List<string> lineIDs, string whLoginID)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string returnValue = string.Empty;
            decimal dQty = 0M;
            try
            {
                int LineID = orderDetailDA.GetMaxOrderDetailLineID(dataBase, tran, orderIDs[0], whLoginID);
                for (int i = 0; lineIDs.Count > i; i++)
                {
                    OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(dataBase, tran, orderIDs[0], lineIDs[i], whLoginID, this.pubParasInfo);
                    dQty = orderDetailInfo.OriginalQty;
                    BomInfo bomInfo = bomDA.GetBomByID(dataBase, tran, orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                    if (bomInfo != null)
                    {
                        bomInfo.BomDetailInfo = bomDetailDA.GetBomDetailListByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, whLoginID);
                        if (bomInfo.BomDetailInfo.Count > 0)
                        {
                            orderDetailDA.DeleteOrderDetail(dataBase, tran, new List<string> { orderDetailInfo.OrderID }, new List<string> { orderDetailInfo.LineID.ToString() }, this.dataBaseID);
                            foreach (BomDetailInfo info in bomInfo.BomDetailInfo)
                            {
                                SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, info.OwnerID, info.SkuID, whLoginID);
                                if (skuInfo != null)
                                {
                                    PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuInfo.PackID, whLoginID);
                                    LineID += 10;
                                    orderDetailInfo.LineID = LineID;
                                    orderDetailInfo.SkuID = info.ComponentSkuID;
                                    orderDetailInfo.OriginalQty = dQty * info.Qty;
                                    orderDetailInfo.PackID = skuInfo.PackID;
                                    orderDetailInfo.UomID = packInfo.PackUom1;
                                    orderDetailDA.InsertOrderDetail(dataBase, tran, orderDetailInfo, whLoginID);
                                }
                            }
                        }
                        else
                        {
                            returnValue = returnValue + orderDetailInfo.SkuID + ";";
                        }
                    }
                    else
                    {
                        returnValue = returnValue + orderDetailInfo.SkuID + ";";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return returnValue;
        }

        public string ManualAllocate(List<PickDetailInfo> pickDetailInfo)
        {
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            string msgStatus = "0";
            string returnMsg = string.Empty;
            string temp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string whLoginID = this.dataBaseID[0];
            try
            {
                InboundHelper inboundHelper = new InboundHelper();
                Dictionary<string, InvLotInfo> invLotInfoList = new Dictionary<string, InvLotInfo>();
                decimal totalAllocatedQty = 0M;
                foreach (PickDetailInfo info in pickDetailInfo)
                {
                    if (!(msgStatus == "0"))
                    {
                        break;
                    }
                    InvLotInfo invLotInfo = null;
                    if (invLotInfoList.ContainsKey(info.Lot))
                    {
                        invLotInfoList.TryGetValue(info.Lot, out invLotInfo);
                    }
                    else
                    {
                        invLotInfo = invLotDA.GetInvLotByID(dataBase, tran, info.Lot, whLoginID);
                        invLotInfoList.Add(info.Lot, invLotInfo);
                    }
                    decimal lotAvailableQty = ((invLotInfo.Qty - invLotInfo.PreallocatedQty) - invLotInfo.AllocatedQty) - invLotInfo.PickedQty;
                    InvLotLocLpnInfo tempInvLotLocLpnInfo = invLotLocLpnDA.GetInvLotLocLpnByID(dataBase, tran, info.Lot, info.Loc, info.LpnID, whLoginID);
                    if (tempInvLotLocLpnInfo != null)
                    {
                        decimal lotLocLpnAvailableQty = ((((tempInvLotLocLpnInfo.Qty - tempInvLotLocLpnInfo.AllocatedQty) - tempInvLotLocLpnInfo.PickedQty) - tempInvLotLocLpnInfo.ExpectedQty) - tempInvLotLocLpnInfo.PickinprocessQty) - tempInvLotLocLpnInfo.PendingMoveIn;
                        if (lotLocLpnAvailableQty <= lotAvailableQty)
                        {
                            if (lotLocLpnAvailableQty >= info.Qty)
                            {
                                invLotInfo.AllocatedQty += info.Qty;
                                invLotInfoList.Remove(info.Lot);
                                invLotInfoList.Add(info.Lot, invLotInfo);
                                info.UomQty = info.Qty;
                                info.Qty = inboundHelper.ExchangeUom(dataBase, tran, info.PackID, info.UomID, info.Qty, "W", whLoginID);
                                info.ToLoc = this.GetDetailPickToLocByFromLoc(dataBase, tran, info.Loc, whLoginID);
                                info.Status = PickDetailStatus.New;
                                info.PreallocatePickDetailID = "";
                                info.PickDetailID = commonMethod.GenNextNumStr(dataBase, tran, "PICK_DETAIL", whLoginID);
                                if (pickDetailDa.InsertPickDetail(dataBase, tran, info, whLoginID) > 0)
                                {
                                    temp = temp + info.PickDetailID + ",";
                                }
                                InvLotInfo invLotinfo = new InvLotInfo {
                                    Lot = info.Lot,
                                    UpdatedBy = info.UpdatedBy,
                                    AllocatedQty = info.Qty,
                                    AllocatedGrossWgt = 0.0,
                                    AllocatedNetWgt = 0.0
                                };
                                invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.AllocatedQtyWgtOnly, whLoginID);
                                InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                    Lot = info.Lot,
                                    Loc = info.Loc,
                                    LpnID = info.LpnID,
                                    AllocatedQty = info.Qty,
                                    UpdatedBy = info.UpdatedBy
                                };
                                invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.AllocatedQty, whLoginID);
                                InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                                    Loc = info.Loc,
                                    SkuID = info.SkuID,
                                    OwnerID = info.OwnerID,
                                    UpdatedBy = info.UpdatedBy,
                                    AllocatedQty = info.Qty
                                };
                                invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.AllocatedQty, whLoginID);
                                totalAllocatedQty += info.Qty;
                            }
                        }
                        else
                        {
                            msgStatus = "1";
                            returnMsg = string.Concat(new object[] { "Error:分配失败! 货位", info.Loc, ",批次号", info.Lot, " 的库存记录可用数量不足,其中有预分配数量", invLotInfo.PreallocatedQty, "." });
                        }
                    }
                }
                if (msgStatus == "0")
                {
                    OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(dataBase, tran, pickDetailInfo[0].OrderID, pickDetailInfo[0].OrderLineID.ToString(), whLoginID, this.pubParasInfo);
                    orderDetailInfo.AllocatedQty += totalAllocatedQty;
                    string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                    orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo[0].OrderID, pickDetailInfo[0].OrderLineID.ToString(), orderDetailStatus, totalAllocatedQty, this.pubParasInfo.UserID, OrderDetailUpdateType.AllocatedQtyOnly, whLoginID);
                    string orderStatus = orderBll.GetOrderStatus(dataBase, tran, pickDetailInfo[0].OrderID, whLoginID, this.pubParasInfo);
                    ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo[0].OrderID, orderStatus, pickDetailInfo[0].UpdatedBy, whLoginID);
                    OrdersInfo ordersInfo4Status = this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo[0].OrderID, pickDetailInfo[0].OrderLineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                    this.UpdateSalesOrderStatus(dataBase, tran, ordersInfo4Status.OrderID, whLoginID, this.pubParasInfo);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            string result = string.Empty;
            switch (msgStatus)
            {
                case "0":
                    return ((temp.Length > 0) ? temp.Substring(0, temp.Length - 1) : temp);

                case "1":
                    result = returnMsg;
                    break;
            }
            return result;
        }

        public string OrganizeRotationRule(RotationRuleInfo rotationRuleInfo)
        {
            string sqlOrderBy = string.Empty;
            if (rotationRuleInfo == null)
            {
                return sqlOrderBy;
            }
            sqlOrderBy = " ORDER BY ";
            if ((rotationRuleInfo.RotationRuleDetailInfo != null) && (rotationRuleInfo.RotationRuleDetailInfo.Count > 0))
            {
                bool flag = false;
                for (int i = 0; i < rotationRuleInfo.RotationRuleDetailInfo.Count; i++)
                {
                    if (rotationRuleInfo.RotationRuleDetailInfo[i].IsActive.ToUpper() == "Y")
                    {
                        string CS00002 = sqlOrderBy;
                        sqlOrderBy = CS00002 + rotationRuleInfo.RotationRuleDetailInfo[i].LotAttributes + " " + rotationRuleInfo.RotationRuleDetailInfo[i].Rotation + ",";
                        flag = true;
                    }
                }
                if (flag)
                {
                    return (sqlOrderBy + " LOT ASC ");
                }
                return (sqlOrderBy + " LOT ASC ");
            }
            return (sqlOrderBy + " LOT ASC ");
        }

        public string OrganizeRotationRule(DataBase database, DbTransaction tran, string rotataionRuleID, string whLoginID)
        {
            string sqlOrderBy = string.Empty;
            RotationRuleInfo rotationRuleInfo = rotataionRuleDA.GetRotationRuleByID(database, tran, rotataionRuleID, whLoginID);
            if (rotationRuleInfo != null)
            {
                rotationRuleInfo.RotationRuleDetailInfo = rotataionRuleDetailDA.GetRotationRuleDetailListByID(database, tran, rotataionRuleID, whLoginID);
                sqlOrderBy = this.OrganizeRotationRule(rotationRuleInfo);
            }
            return sqlOrderBy;
        }

        private decimal PreAllocateByStrategy(DataBase database, DbTransaction tran, string preallocateStrategy, OrderDetailInfo orderDetailInfo, List<InvLotInfo> invLotInfos, PackInfo packInfo, SkuInfo skuInfo, decimal remainQty, string updatedBy, string whLoginID)
        {
            decimal factor = 0M;
            decimal orderPackQty = 0M;
            decimal invLotPackQty = 0M;
            factor = Convert.ToDecimal(this.ExchangeAllocateStratetyUom2PackFactor(packInfo, preallocateStrategy));
            if (factor != 0M)
            {
                if (remainQty < factor)
                {
                    return remainQty;
                }
                orderPackQty = Math.Floor((decimal) (remainQty / factor));
                remainQty -= orderPackQty * factor;
                if (skuInfo.ShelfLifeIndicator == "Y")
                {
                    if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                    {
                        if (skuInfo.ShelfLife > 0)
                        {
                            invLotInfos = invLotInfos.FindAll(x => DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife)) < lotAttributeDA.GetLotAttributeByID(database, tran, x.Lot, whLoginID).ExpiryDate);
                        }
                    }
                    else if (skuInfo.ShelfLife > 0)
                    {
                        invLotInfos = invLotInfos.FindAll(x => DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife)) < lotAttributeDA.GetLotAttributeByID(database, tran, x.Lot, whLoginID).ProduceDate);
                    }
                }
                foreach (InvLotInfo invLotInfo in invLotInfos)
                {
                    decimal invlotAvailableQty = (((invLotInfo.Qty - invLotInfo.PreallocatedQty) - invLotInfo.AllocatedQty) - invLotInfo.PickedQty) - invLotInfo.OnholdQty;
                    if (invlotAvailableQty > 0M)
                    {
                        invLotPackQty = Math.Floor((decimal) (invlotAvailableQty / factor));
                        if (invLotPackQty > 0M)
                        {
                            decimal deductInvLotPreAllocateQty = 0M;
                            decimal tempInvLotPreallocateQty = 0M;
                            if (invLotPackQty >= orderPackQty)
                            {
                                deductInvLotPreAllocateQty = orderPackQty * factor;
                                tempInvLotPreallocateQty = invLotInfo.PreallocatedQty + (orderPackQty * factor);
                                orderPackQty = 0M;
                            }
                            else
                            {
                                orderPackQty -= invLotPackQty;
                                deductInvLotPreAllocateQty = invLotPackQty * factor;
                                tempInvLotPreallocateQty = invLotInfo.PreallocatedQty + (invLotPackQty * factor);
                            }
                            this.InsertPreallocatePickDetailByOrderDetailandInvLot(database, tran, orderDetailInfo, invLotInfo, deductInvLotPreAllocateQty, preallocateStrategy, deductInvLotPreAllocateQty / factor, updatedBy, whLoginID);
                            invLotInfo.PreallocatedQty = deductInvLotPreAllocateQty;
                            invLotInfo.PreallocatedGrossWgt = Convert.ToDouble((decimal) (deductInvLotPreAllocateQty * Convert.ToDecimal(skuInfo.GrossWgt)));
                            invLotInfo.PreallocatedNetWgt = Convert.ToDouble((decimal) (deductInvLotPreAllocateQty * Convert.ToDecimal(skuInfo.NetWgt)));
                            invLotDA.UpdateInvLot(database, tran, invLotInfo, InvLotUpdateType.PreAllocatedQtyWgt, whLoginID);
                            invLotInfo.PreallocatedQty = tempInvLotPreallocateQty;
                        }
                        if (orderPackQty == 0M)
                        {
                            break;
                        }
                    }
                }
                if (orderPackQty > 0M)
                {
                    remainQty += orderPackQty * factor;
                }
            }
            return remainQty;
        }

        public string PreallocatedByOrderDetail(OrderDetailInfo orderDetailInfo, OrderDetailBLL orderDetailBLL, PreallocateRuleInfo preAllocateRuleInfo, PackInfo packInfo, SkuInfo skuInfo, string updatedBy, string whLoginID, ref bool successFlag)
        {
            string temp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                decimal revertOrderDetailQty = this.RevertOrderDetailPreAllocate(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), whLoginID);
                orderDetailInfo.PreallocatedQty -= revertOrderDetailQty;
                List<InvLotInfo> invLotInfos = this.GetInvLotByLotAttribute(dataBase, tran, orderDetailInfo, whLoginID);
                if ((invLotInfos == null) || (invLotInfos.Count <= 0))
                {
                    throw new Exception(PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_017", this.pubParasInfo.UserLanguage));
                }
                if (((preAllocateRuleInfo == null) || (preAllocateRuleInfo.PreallocateRuleDetailInfos == null)) || (preAllocateRuleInfo.PreallocateRuleDetailInfos.Count <= 0))
                {
                    throw new Exception(PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_014", this.pubParasInfo.UserLanguage));
                }
                decimal availablePreallocateQty = ((orderDetailInfo.OriginalQty - orderDetailInfo.ShippedQty) - orderDetailInfo.AllocatedQty) - orderDetailInfo.PickedQty;
                decimal remainQty = availablePreallocateQty;
                foreach (PreallocateRuleDetailInfo preAllocateRuleDetail in preAllocateRuleInfo.PreallocateRuleDetailInfos)
                {
                    if (preAllocateRuleDetail.IsActive == "Y")
                    {
                        remainQty = this.PreAllocateByStrategy(dataBase, tran, preAllocateRuleDetail.UomID, orderDetailInfo, invLotInfos, packInfo, skuInfo, remainQty, updatedBy, whLoginID);
                    }
                    if (remainQty == 0M)
                    {
                        break;
                    }
                }
                if (remainQty == availablePreallocateQty)
                {
                    throw new Exception(PublicMethod.GetInstance().GetGlobalMsgResource("F7100_011", this.pubParasInfo.UserLanguage) + orderDetailInfo.LineID.ToString() + PublicMethod.GetInstance().GetGlobalMsgResource("F7100_013", this.pubParasInfo.UserLanguage));
                }
                if (remainQty > 0M)
                {
                    orderDetailInfo.PreallocatedQty = availablePreallocateQty - remainQty;
                    orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), OrderStatus.PartPreAllocated, orderDetailInfo.PreallocatedQty, updatedBy, OrderDetailUpdateType.PreAllocatedQty, whLoginID);
                    this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), OrderStatus.PartPreAllocated, 0M, whLoginID, this.pubParasInfo);
                    successFlag = true;
                }
                else if (remainQty == 0M)
                {
                    orderDetailInfo.PreallocatedQty += availablePreallocateQty;
                    string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                    orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, availablePreallocateQty, updatedBy, OrderDetailUpdateType.PreAllocatedQty, whLoginID);
                    this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                    successFlag = true;
                }
                tran.Commit();
                return temp;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                temp = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string ReleasePcTasks(List<string> RequestID, string updateBy, string PcStatus)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string StrType = string.Empty;
            if (PcStatus.ToUpper() == "CRELEASED")
            {
                StrType = TaskType.PC;
            }
            if (PcStatus.ToUpper() == "RCRELEASED")
            {
                StrType = TaskType.PR;
            }
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; RequestID.Count > i; i++)
                {
                    RequestDA.UpdatePhysicalRequestStatus(dataBase, tran, RequestID[i], PcStatus, whLoginID);
                    TagDA.UpdatePhysicalTagStatus(dataBase, tran, RequestID[i], PcStatus, whLoginID);
                    List<PhysicalTagInfo> tagList = TagDA.GetPhysicalTagListByID(dataBase, tran, RequestID[i], whLoginID, this.pubParasInfo);
                    foreach (PhysicalTagInfo info in tagList)
                    {
                        TaskDetailInfo taskDetailEntity = new TaskDetailInfo {
                            TaskDetailID = commonMethod.GenNextNumStr("TASK_DETAIL", whLoginID),
                            TaskType = StrType,
                            OwnerID = info.OwnerID,
                            SkuID = info.SkuID,
                            Lot = info.Lot,
                            UomID = info.UomID,
                            Qty = info.SysQty,
                            FromLoc = info.Loc,
                            LogicalFromLoc = "",
                            FromLpnID = info.LpnID,
                            ToLoc = "",
                            LogicalToLoc = "",
                            ToLpnID = "",
                            CaseID = "",
                            PickMethod = "",
                            Status = TaskStatus.Pending,
                            StatusMsg = "",
                            Priority = TaskPriority.five,
                            SourcePriority = "",
                            HoldID = "",
                            UserID = "",
                            UserPosition = "",
                            UserIdOverride = "",
                            StartTime = DateTime.Now,
                            EndTime = DateTime.Now,
                            SourceType = "",
                            DocID = info.PhysicalRequestID,
                            DocLineID = info.TagNo,
                            PickDetailID = "",
                            OrderID = "",
                            OrderLineID = 0,
                            ListID = "",
                            WaveID = "",
                            ReasonID = "",
                            Message01 = "",
                            Message02 = "",
                            Message03 = "",
                            FinalToLoc = "",
                            FromTransID = "",
                            CreatedBy = updateBy,
                            UpdatedBy = updateBy
                        };
                        taskDetailDa.InsertTaskDetail(dataBase, tran, taskDetailEntity, whLoginID);
                        temp = temp + taskDetailEntity.TaskDetailID;
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string ReleasePickTasks(List<string> pickDetailID, string updateBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; pickDetailID.Count > i; i++)
                {
                    pickDetailDa.UpdatePickDetailStatus(dataBase, tran, pickDetailID[i], PickDetailStatus.Released, updateBy, whLoginID);
                    PickDetailInfo info = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    TaskDetailInfo taskDetailEntity = new TaskDetailInfo {
                        TaskDetailID = commonMethod.GenNextNumStr("TASK_DETAIL", whLoginID),
                        TaskType = TaskType.PK,
                        OwnerID = info.OwnerID,
                        SkuID = info.SkuID,
                        Lot = info.Lot,
                        UomID = info.UomID,
                        UomQty = info.UomQty,
                        Qty = info.Qty,
                        FromLoc = info.Loc,
                        LogicalFromLoc = info.Loc,
                        FromLpnID = info.LpnID,
                        ToLoc = info.ToLoc,
                        LogicalToLoc = info.ToLoc,
                        ToLpnID = info.LpnID,
                        CaseID = info.CaseID,
                        PickMethod = info.PickMethod,
                        Status = TaskStatus.Pending,
                        StatusMsg = "",
                        Priority = TaskPriority.five,
                        SourcePriority = "",
                        HoldID = "",
                        UserID = "",
                        UserPosition = "",
                        UserIdOverride = "",
                        StartTime = DateTime.Now,
                        EndTime = DateTime.Now,
                        SourceType = "",
                        DocID = info.OrderID,
                        DocLineID = info.OrderLineID,
                        PickDetailID = info.PickDetailID,
                        OrderID = info.OrderID,
                        OrderLineID = info.OrderLineID,
                        ListID = "",
                        WaveID = "",
                        ReasonID = "",
                        Message01 = "",
                        Message02 = "",
                        Message03 = "",
                        FinalToLoc = "",
                        FromTransID = "",
                        CreatedBy = updateBy,
                        UpdatedBy = updateBy
                    };
                    taskDetailDa.InsertTaskDetail(dataBase, tran, taskDetailEntity, whLoginID);
                    temp = temp + taskDetailEntity.TaskDetailID;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string ReleasePickTasks(List<string> pickDetailID, string userID, string updateBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; pickDetailID.Count > i; i++)
                {
                    pickDetailDa.UpdatePickDetailStatus(dataBase, tran, pickDetailID[i], PickDetailStatus.Released, updateBy, whLoginID);
                    PickDetailInfo info = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    TaskDetailInfo taskDetailEntity = new TaskDetailInfo {
                        TaskDetailID = commonMethod.GenNextNumStr("TASK_DETAIL", whLoginID),
                        TaskType = TaskType.PK,
                        OwnerID = info.OwnerID,
                        SkuID = info.SkuID,
                        Lot = info.Lot,
                        UomID = info.UomID,
                        UomQty = info.UomQty,
                        Qty = info.Qty,
                        FromLoc = info.Loc,
                        LogicalFromLoc = info.Loc,
                        FromLpnID = info.LpnID,
                        ToLoc = info.ToLoc,
                        LogicalToLoc = info.ToLoc,
                        ToLpnID = info.LpnID,
                        CaseID = info.CaseID,
                        PickMethod = info.PickMethod,
                        Status = TaskStatus.Pending,
                        StatusMsg = "",
                        Priority = TaskPriority.five,
                        SourcePriority = "",
                        HoldID = "",
                        UserID = userID,
                        UserPosition = "",
                        UserIdOverride = "",
                        StartTime = DateTime.Now,
                        EndTime = DateTime.Now,
                        SourceType = "",
                        DocID = info.OrderID,
                        DocLineID = info.OrderLineID,
                        PickDetailID = info.PickDetailID,
                        OrderID = info.OrderID,
                        OrderLineID = info.OrderLineID,
                        ListID = "",
                        WaveID = "",
                        ReasonID = "",
                        Message01 = "",
                        Message02 = "",
                        Message03 = "",
                        FinalToLoc = "",
                        FromTransID = "",
                        CreatedBy = updateBy,
                        UpdatedBy = updateBy
                    };
                    taskDetailDa.InsertTaskDetail(dataBase, tran, taskDetailEntity, whLoginID);
                    temp = temp + taskDetailEntity.TaskDetailID;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string RevertAllocate(List<string> pickDetailIDS, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            try
            {
                List<PickDetailInfo> pickDetailInfos = pickDetailDa.GetPickDetailsByID(pickDetailIDS, whLoginID, this.pubParasInfo);
                temp = this.RevertAllocate(pickDetailInfos, updatedBy);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string RevertAllocate(List<PickDetailInfo> pickDetailInfos, string updatedBy)
        {
            string result = string.Empty;
            if ((pickDetailInfos != null) && (pickDetailInfos.Count > 0))
            {
                int i;
                string whLoginID = this.dataBaseID[0];
                List<string> orderIDList = new List<string>();
                OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                for (i = 0; i < pickDetailInfos.Count; i++)
                {
                    if (pickDetailInfos[i].Status == PickDetailStatus.New)
                    {
                        if (!orderIDList.Contains(pickDetailInfos[i].OrderID))
                        {
                            orderIDList.Add(pickDetailInfos[i].OrderID);
                        }
                        if (orderDetailDA.RevertOrderDetailAllocate(pickDetailInfos[i], whLoginID, this.pubParasInfo))
                        {
                            OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(pickDetailInfos[i].OrderID, pickDetailInfos[i].OrderLineID.ToString(), whLoginID, this.pubParasInfo);
                            string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                            orderDetailDA.UpdateOrderDetailStatus(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, updatedBy, whLoginID);
                            if (orderDetailInfo.BatchFlag == "Y")
                            {
                                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailInfo.Status, updatedBy, whLoginID);
                            }
                            this.UpdateSalesOrderDetailStatusAndQty(orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                            result = result + pickDetailInfos[i].PickDetailID + ",";
                        }
                    }
                }
                if ((orderIDList != null) && (orderIDList.Count > 0))
                {
                    WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
                    for (i = 0; i < orderIDList.Count; i++)
                    {
                        string orderStatus = orderBll.GetOrderStatus(orderIDList[i], whLoginID, this.pubParasInfo);
                        ordersDA.UpdateOrdersStatus(orderIDList[i], orderStatus, updatedBy, whLoginID);
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(orderIDList[i], orderStatus, updatedBy, whLoginID);
                        wavebll.UpdateWaveStatusByOrderID(orderIDList[i]);
                        this.UpdateSalesOrderStatus(orderIDList[i], whLoginID, this.pubParasInfo);
                    }
                }
            }
            return (string.IsNullOrEmpty(result) ? "" : result.Substring(0, result.Length - 1));
        }

        public decimal RevertOrderDetailPreAllocate(DataBase dataBase, DbTransaction tran, string orderID, string orderLineID, string whLoginID)
        {
            return orderDetailDA.RevertOrderDetailPreAllocate(dataBase, tran, orderID, orderLineID, whLoginID, this.pubParasInfo);
        }

        public string RevertPicked(List<string> pickDetailID, string updateBy)
        {
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL(this.pubParasInfo);
            WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < pickDetailID.Count; i++)
                {
                    PickDetailInfo pickDetailInfo = pickDetailDa.GetPickDetailByID(dataBase, tran, pickDetailID[i], whLoginID, this.pubParasInfo);
                    if (pickDetailInfo.Status == PickDetailStatus.Picked)
                    {
                        List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                        OrderDetailInfo orderDetailInfo = null;
                        for (int j = 0; j < orderDetailInfos.Count; j++)
                        {
                            if (orderDetailInfos[j].LineID == pickDetailInfo.OrderLineID)
                            {
                                OrderDetailInfo local1 = orderDetailInfos[j];
                                local1.PickedQty -= pickDetailInfo.Qty;
                                OrderDetailInfo local2 = orderDetailInfos[j];
                                local2.AllocatedQty += pickDetailInfo.Qty;
                                orderDetailInfo = orderDetailInfos[j];
                                break;
                            }
                        }
                        this.InsertRevertPickTasks(dataBase, tran, pickDetailInfo, this.pubParasInfo.UserID, whLoginID);
                        pickDetailDa.UpdatePickDetailStatusAndPickToLoc(dataBase, tran, pickDetailID[i], PickDetailStatus.New, pickDetailInfo.ToLoc, updateBy, whLoginID);
                        InvLotInfo invLotinfo = new InvLotInfo {
                            Lot = pickDetailInfo.Lot,
                            UpdatedBy = updateBy,
                            PickedQty = pickDetailInfo.Qty * -1M,
                            PickedGrossWgt = 0.0,
                            PickedNetWgt = 0.0
                        };
                        invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.PickedQtyWgt, whLoginID);
                        InvMovesInfo invMovesInfo = new InvMovesInfo {
                            FromLoc = pickDetailInfo.ToLoc,
                            FromLot = pickDetailInfo.Lot,
                            FromLpn = pickDetailInfo.LpnID,
                            FromOwnerID = pickDetailInfo.OwnerID,
                            FromSkuID = pickDetailInfo.SkuID,
                            MoveQty = pickDetailInfo.Qty,
                            FromMoveQty = pickDetailInfo.Qty,
                            PackID = pickDetailInfo.PackID,
                            ToLoc = pickDetailInfo.Loc,
                            ToLot = pickDetailInfo.Lot,
                            ToLpn = pickDetailInfo.LpnID,
                            ToOwnerID = pickDetailInfo.OwnerID,
                            ToSkuID = pickDetailInfo.SkuID,
                            UomID = pickDetailInfo.UomID,
                            UpdatedBy = updateBy
                        };
                        inventoryMgtBll.UpdateInvLotLocLpn4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                        InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                            Lot = pickDetailInfo.Lot,
                            Loc = pickDetailInfo.Loc,
                            LpnID = pickDetailInfo.LpnID,
                            AllocatedQty = pickDetailInfo.Qty * -1M,
                            UpdatedBy = updateBy
                        };
                        invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.FromLocAllocatedQty, whLoginID);
                        invLotLocLpnInfo.Loc = pickDetailInfo.ToLoc;
                        invLotLocLpnInfo.PickedQty = pickDetailInfo.Qty * -1M;
                        invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.ToLocPickedQty, whLoginID);
                        inventoryMgtBll.UpdateInvSkuLoc4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                        InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                            Loc = pickDetailInfo.Loc,
                            SkuID = pickDetailInfo.SkuID,
                            OwnerID = pickDetailInfo.OwnerID,
                            UpdatedBy = updateBy,
                            AllocatedQty = pickDetailInfo.Qty * -1M
                        };
                        invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.FromLocAllocatedQty, whLoginID);
                        invskulocInfo.Loc = pickDetailInfo.ToLoc;
                        invskulocInfo.PickedQty = pickDetailInfo.Qty * -1M;
                        invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.ToLocPickedQty, whLoginID);
                        string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                        orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty * -1M, updateBy, OrderDetailUpdateType.PickedQty, whLoginID);
                        string orderStatus = orderBll.GetOrderStatus(orderDetailInfos);
                        ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                        wavebll.UpdateWaveStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID);
                        OrdersInfo ordersInfo4Status = this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                        this.UpdateSalesOrderStatus(dataBase, tran, ordersInfo4Status.OrderID, whLoginID, this.pubParasInfo);
                        temp = temp + pickDetailID[i] + ",";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ((temp.Length > 0) ? temp.Substring(0, temp.Length - 1) : "");
        }

        public string RevertPickedAllocated(List<string> pickDetailID)
        {
            try
            {
                this.RevertPicked(pickDetailID, this.pubParasInfo.UserID);
                return this.RevertAllocate(pickDetailID, this.pubParasInfo.UserID);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

        public string RevertPreAllocate(string orderID, List<string> orderLineID, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            try
            {
                string where = " AND OD.STATUS <> 'SHIPPED' AND OD.LINE_ID IN ('";
                if ((orderLineID != null) && (orderLineID.Count > 0))
                {
                    for (int i = 0; i < orderLineID.Count; i++)
                    {
                        where = where + orderLineID[i] + "','";
                    }
                    where = where.Substring(0, where.Length - 2) + ")";
                }
                else
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_010", this.pubParasInfo.UserLanguage);
                }
                List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, where, whLoginID, this.pubParasInfo);
                if ((orderDetailInfos == null) || (orderDetailInfos.Count <= 0))
                {
                    return temp;
                }
                OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
                foreach (OrderDetailInfo orderDetailInfo in orderDetailInfos)
                {
                    if (orderDetailInfo.PreallocatedQty > 0M)
                    {
                        DataBase dataBase = new DataBase();
                        DbConnection conn = dataBase.connection;
                        conn.Open();
                        DbTransaction tran = conn.BeginTransaction();
                        try
                        {
                            decimal revertPreAllocateQty = this.RevertOrderDetailPreAllocate(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), whLoginID);
                            orderDetailInfo.PreallocatedQty -= revertPreAllocateQty;
                            string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                            orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, revertPreAllocateQty * -1M, updatedBy, OrderDetailUpdateType.Status, whLoginID);
                            this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, orderDetailInfo.OrderID, orderDetailInfo.LineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                            if (orderDetailInfo.BatchFlag == "Y")
                            {
                                waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, orderID, orderDetailInfo.LineID.ToString(), orderDetailInfo.Status, updatedBy, whLoginID);
                            }
                            temp = temp + orderDetailInfo.LineID.ToString() + ",";
                            tran.Commit();
                        }
                        catch
                        {
                            tran.Rollback();
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
                string orderStatus = new OrdersBLL().GetOrderStatus(orderID, whLoginID, this.pubParasInfo);
                ordersDA.UpdateOrdersStatus(orderID, orderStatus, updatedBy, whLoginID);
                this.UpdateSalesOrderStatus(orderID, whLoginID, this.pubParasInfo);
                waveDetailDA.UpdateWaveDetailStatusByOrderID(orderID, orderStatus, updatedBy, whLoginID);
                new WaveBLL(this.pubParasInfo).UpdateWaveStatusByOrderID(orderID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return temp;
        }

        public string ShippedByOrderID(List<string> orderID, string shippDate, string updatedBy)
        {
            string temp = string.Empty;
            for (int i = 0; i < orderID.Count; i++)
            {
                List<string> orderLineIDs = orderDetailDA.GetOrderLineIDByOrderID4Shipping(orderID[i], this.dataBaseID[0]);
                if (((orderLineIDs != null) && (orderLineIDs.Count > 0)) && !string.IsNullOrEmpty(this.ShippedByOrderLineID(orderID[i], shippDate, orderLineIDs, updatedBy)))
                {
                    temp = temp + orderID[i] + ",";
                }
            }
            return ((temp.Length == 0) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string ShippedByOrderLineID(string orderID, string shippDate, List<string> orderLineIDs, string updatedBy)
        {
            int i;
            string temp = string.Empty;
            List<string> pickDetailIDs = new List<string>();
            for (i = 0; i < orderLineIDs.Count; i++)
            {
                List<string> tempPickDetailIDs = new List<string>();
                tempPickDetailIDs = pickDetailDa.GetPickDetailIDByOrderLineID(orderID, orderLineIDs[i], OrderStatus.Picked, this.dataBaseID[0]);
                if ((tempPickDetailIDs != null) && (tempPickDetailIDs.Count > 0))
                {
                    for (int j = 0; j < tempPickDetailIDs.Count; j++)
                    {
                        pickDetailIDs.Add(tempPickDetailIDs[j]);
                    }
                }
            }
            if (((pickDetailIDs != null) && (pickDetailIDs.Count > 0)) && !string.IsNullOrEmpty(this.ConfirmShipped(pickDetailIDs, shippDate, updatedBy)))
            {
                for (i = 0; i < orderLineIDs.Count; i++)
                {
                    temp = temp + orderLineIDs[i] + ",";
                }
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", this.dataBaseID[0], this.pubParasInfo);
            if ((sysSettinginfo != null) && (sysSettinginfo.Value == "Y"))
            {
                OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderID, this.dataBaseID[0], this.pubParasInfo);
                if (ordersInfo.Status.ToUpper() == "SHIPPED")
                {
                    ordersInfo.Udf10 = new CEABLL(this.pubParasInfo).ShippingDelivery(ordersInfo);
                }
            }
            return ((temp.Length == 0) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string ShippedByOrderLineID(string orderID, List<string> orderLineIDs, List<decimal> qtys, string shippDate, string updatedBy)
        {
            int i;
            string temp = string.Empty;
            List<string> pickDetailIDs = new List<string>();
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                i = 0;
                while (i < orderLineIDs.Count)
                {
                    List<string> tempPickDetailIDs = new List<string>();
                    tempPickDetailIDs = pickDetailDa.GetPickDetailIDByOrderLineID(db, tran, orderID, orderLineIDs[i], OrderStatus.Picked, this.dataBaseID[0]);
                    List<PickDetailInfo> pickDetailInfos = pickDetailDa.GetPickDetailsByID(db, tran, tempPickDetailIDs, this.dataBaseID[0], this.pubParasInfo);
                    decimal shipQty = 0M;
                    if ((pickDetailInfos != null) && (pickDetailInfos.Count > 0))
                    {
                        for (int j = 0; j < pickDetailInfos.Count; j++)
                        {
                            PickDetailInfo pickDetailInfo = pickDetailInfos[j];
                            shipQty += pickDetailInfo.Qty;
                            if (shipQty == qtys[i])
                            {
                                pickDetailIDs.Add(pickDetailInfo.PickDetailID);
                                break;
                            }
                            if (shipQty < qtys[i])
                            {
                                pickDetailIDs.Add(pickDetailInfo.PickDetailID);
                            }
                            else
                            {
                                decimal diffQty = shipQty - qtys[i];
                                pickDetailDa.UpdatePickDetailQty(db, tran, pickDetailInfo.PickDetailID, pickDetailInfo.Qty - diffQty, updatedBy, this.dataBaseID[0]);
                                invTransDA.UpdateInvTransPickedQty(db, tran, pickDetailInfo.PickDetailID, pickDetailInfo.Qty - diffQty, updatedBy, this.dataBaseID[0]);
                                pickDetailIDs.Add(pickDetailInfo.PickDetailID);
                                decimal rate = pickDetailInfo.UomQty / pickDetailInfo.Qty;
                                pickDetailInfo.PickDetailID = commonMethod.GenNextNumStr(db, tran, "PICK_DETAIL", this.dataBaseID[0]);
                                pickDetailInfo.Qty = diffQty;
                                pickDetailInfo.UomQty = diffQty * rate;
                                pickDetailInfo.CreatedBy = updatedBy;
                                pickDetailInfo.CreatedDate = DateTime.Now;
                                pickDetailInfo.UpdatedBy = updatedBy;
                                pickDetailInfo.UpdatedDate = DateTime.Now;
                                pickDetailDa.InsertPickDetail(db, tran, pickDetailInfo, this.dataBaseID[0]);
                                this.InsertConfirmPickedAndShippedTrans(db, tran, pickDetailInfo, "Picked", "", this.dataBaseID[0]);
                                break;
                            }
                        }
                    }
                    i++;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (((pickDetailIDs != null) && (pickDetailIDs.Count > 0)) && !string.IsNullOrEmpty(this.ConfirmShipped(pickDetailIDs, shippDate, updatedBy)))
            {
                for (i = 0; i < orderLineIDs.Count; i++)
                {
                    temp = temp + orderLineIDs[i] + ",";
                }
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", this.dataBaseID[0], this.pubParasInfo);
            if ((sysSettinginfo != null) && (sysSettinginfo.Value == "Y"))
            {
                OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderID, this.dataBaseID[0], this.pubParasInfo);
                if (ordersInfo.Status.ToUpper() == "SHIPPED")
                {
                    ordersInfo.Udf10 = new CEABLL(this.pubParasInfo).ShippingDelivery(ordersInfo);
                }
            }
            return ((temp.Length == 0) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string ShippingCarriersAssigned(List<string> orderID)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < orderID.Count; i++)
                {
                    OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderID[i], whLoginID, this.pubParasInfo);
                    if (ordersInfo != null)
                    {
                        DistributionRangeInfo distributionRangeInfo = iDistributionRangeDA.GetDistributionRangeInfoByShipping(dataBase, tran, ordersInfo.CCity, ordersInfo.CCounties, ordersInfo.CProv, whLoginID);
                        if (distributionRangeInfo != null)
                        {
                            string strCattierID = !string.IsNullOrEmpty(distributionRangeInfo.CarrierID) ? distributionRangeInfo.CarrierID : distributionRangeInfo.AlternateCarrierID;
                            if (ordersDA.UpdateOrderCarrierIDByOrderID(dataBase, tran, orderID[i], strCattierID, this.pubParasInfo.UserID, whLoginID) > 0)
                            {
                                temp = temp + orderID[i] + ",";
                            }
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string ShippingWeightCancelOrder(List<string> orderID)
        {
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL(this.pubParasInfo);
            OrdersBLL orderBll = new OrdersBLL(this.pubParasInfo);
            InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL(this.pubParasInfo);
            WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
            string updateBy = this.pubParasInfo.UserID;
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < orderID.Count; i++)
                {
                    List<PickDetailInfo> pickDetailList = pickDetailDa.GetPickDetailByOrderID(dataBase, tran, orderID[i], whLoginID, this.pubParasInfo);
                    foreach (PickDetailInfo pickDetailInfo in pickDetailList)
                    {
                        if (pickDetailInfo.Status == PickDetailStatus.Picked)
                        {
                            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, pickDetailInfo.OrderID, whLoginID, this.pubParasInfo);
                            OrderDetailInfo orderDetailInfo = null;
                            for (int j = 0; j < orderDetailInfos.Count; j++)
                            {
                                if (orderDetailInfos[j].LineID == pickDetailInfo.OrderLineID)
                                {
                                    OrderDetailInfo local1 = orderDetailInfos[j];
                                    local1.PickedQty -= pickDetailInfo.Qty;
                                    OrderDetailInfo local2 = orderDetailInfos[j];
                                    local2.AllocatedQty += pickDetailInfo.Qty;
                                    orderDetailInfo = orderDetailInfos[j];
                                    break;
                                }
                            }
                            this.InsertRevertPickTasks(dataBase, tran, pickDetailInfo, this.pubParasInfo.UserID, whLoginID);
                            pickDetailDa.UpdatePickDetailStatusAndPickToLoc(dataBase, tran, pickDetailInfo.PickDetailID, PickDetailStatus.New, pickDetailInfo.ToLoc, updateBy, whLoginID);
                            InvLotInfo invLotinfo = new InvLotInfo {
                                Lot = pickDetailInfo.Lot,
                                UpdatedBy = updateBy,
                                PickedQty = pickDetailInfo.Qty * -1M,
                                PickedGrossWgt = 0.0,
                                PickedNetWgt = 0.0
                            };
                            invLotDA.UpdateInvLot(dataBase, tran, invLotinfo, InvLotUpdateType.PickedQtyWgt, whLoginID);
                            InvMovesInfo invMovesInfo = new InvMovesInfo {
                                FromLoc = pickDetailInfo.ToLoc,
                                FromLot = pickDetailInfo.Lot,
                                FromLpn = pickDetailInfo.LpnID,
                                FromOwnerID = pickDetailInfo.OwnerID,
                                FromSkuID = pickDetailInfo.SkuID,
                                MoveQty = pickDetailInfo.Qty,
                                FromMoveQty = pickDetailInfo.Qty,
                                PackID = pickDetailInfo.PackID,
                                ToLoc = pickDetailInfo.Loc,
                                ToLot = pickDetailInfo.Lot,
                                ToLpn = pickDetailInfo.LpnID,
                                ToOwnerID = pickDetailInfo.OwnerID,
                                ToSkuID = pickDetailInfo.SkuID,
                                UomID = pickDetailInfo.UomID,
                                UpdatedBy = updateBy
                            };
                            inventoryMgtBll.UpdateInvLotLocLpn4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                            InvLotLocLpnInfo invLotLocLpnInfo = new InvLotLocLpnInfo {
                                Lot = pickDetailInfo.Lot,
                                Loc = pickDetailInfo.Loc,
                                LpnID = pickDetailInfo.LpnID,
                                AllocatedQty = pickDetailInfo.Qty * -1M,
                                UpdatedBy = updateBy
                            };
                            invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.FromLocAllocatedQty, whLoginID);
                            invLotLocLpnInfo.Loc = pickDetailInfo.ToLoc;
                            invLotLocLpnInfo.PickedQty = pickDetailInfo.Qty * -1M;
                            invLotLocLpnDA.UpdateInvLotLocLpn(dataBase, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.ToLocPickedQty, whLoginID);
                            inventoryMgtBll.UpdateInvSkuLoc4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                            InvSkuLocInfo invskulocInfo = new InvSkuLocInfo {
                                Loc = pickDetailInfo.Loc,
                                SkuID = pickDetailInfo.SkuID,
                                OwnerID = pickDetailInfo.OwnerID,
                                UpdatedBy = updateBy,
                                AllocatedQty = pickDetailInfo.Qty * -1M
                            };
                            invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.FromLocAllocatedQty, whLoginID);
                            invskulocInfo.Loc = pickDetailInfo.ToLoc;
                            invskulocInfo.PickedQty = pickDetailInfo.Qty * -1M;
                            invSkuLocDA.UpdateInvSkuLoc(dataBase, tran, invskulocInfo, InvSkuLocUpdateType.ToLocPickedQty, whLoginID);
                            string orderDetailStatus = orderDetailBLL.GetOrderDetailStatus(orderDetailInfo);
                            orderDetailDA.UpdateOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, pickDetailInfo.Qty * -1M, updateBy, OrderDetailUpdateType.PickedQty, whLoginID);
                            string orderStatus = orderBll.GetOrderStatus(orderDetailInfos);
                            ordersDA.UpdateOrdersStatus(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                            waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID, orderStatus, updateBy, whLoginID);
                            wavebll.UpdateWaveStatusByOrderID(dataBase, tran, pickDetailInfo.OrderID);
                            OrdersInfo ordersInfo4Status = this.UpdateSalesOrderDetailStatusAndQty(dataBase, tran, pickDetailInfo.OrderID, pickDetailInfo.OrderLineID.ToString(), orderDetailStatus, 0M, whLoginID, this.pubParasInfo);
                            this.UpdateSalesOrderStatus(dataBase, tran, ordersInfo4Status.OrderID, whLoginID, this.pubParasInfo);
                            temp = temp + pickDetailInfo.PickDetailID + ",";
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string UpateActualShipDateByOrderID(string orderID, string actualShipDate)
        {
            string result = string.Empty;
            string whLoginID = this.dataBaseID[0];
            List<PickDetailInfo> pickDetailInfo = pickDetailDa.GetPickDetailByOrderID(orderID, this.dataBaseID[0], this.pubParasInfo);
            if ((pickDetailInfo != null) && (pickDetailInfo.Count > 0))
            {
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    int i;
                    List<string> orderLineIDList = new List<string>();
                    for (i = 0; i < pickDetailInfo.Count; i++)
                    {
                        if (pickDetailInfo[i].Status == OrderStatus.Shipped)
                        {
                            invTransDA.UpdateTransCreatedDateByDocID(dataBase, tran, pickDetailInfo[i].PickDetailID, TransType.Shipment, TransSourceType.PickingUpdate, this.pubParasInfo.UserID, actualShipDate, whLoginID);
                            pickDetailDa.UpdatePickDetailUpdateDateByPickDetailID(dataBase, tran, pickDetailInfo[i].PickDetailID, actualShipDate, this.pubParasInfo.UserID, whLoginID);
                            if (!orderLineIDList.Contains(pickDetailInfo[i].OrderLineID.ToString()))
                            {
                                orderLineIDList.Add(pickDetailInfo[i].OrderLineID.ToString());
                            }
                        }
                    }
                    if ((orderLineIDList != null) && (orderLineIDList.Count > 0))
                    {
                        for (i = 0; i < orderLineIDList.Count; i++)
                        {
                            orderDetailDA.UpdateOrderDetailActualShipDateByOrderID(dataBase, tran, orderID, orderLineIDList[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                        }
                    }
                    ordersDA.UpdateOrderActualShipDateByOrderID(dataBase, tran, orderID, actualShipDate, this.pubParasInfo.UserID, whLoginID);
                    tran.Commit();
                    result = orderID;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return result;
        }

        public string UpateActualShipDateByOrderID(string orderID, List<string> LineID, string actualShipDate)
        {
            string result = string.Empty;
            string whLoginID = this.dataBaseID[0];
            if ((LineID != null) && (LineID.Count > 0))
            {
                int i;
                string strLineID = " AND PD.ORDER_LINE_ID IN(";
                for (i = 0; i < LineID.Count; i++)
                {
                    strLineID = strLineID + "'" + LineID[i] + "',";
                }
                strLineID = strLineID.Substring(0, strLineID.Length - 1) + ") ";
                List<PickDetailInfo> pickDetailInfo = pickDetailDa.GetPickDetailByOrderID(orderID, strLineID, whLoginID, this.pubParasInfo);
                if ((pickDetailInfo != null) && (pickDetailInfo.Count > 0))
                {
                    DataBase dataBase = new DataBase();
                    DbConnection conn = dataBase.connection;
                    conn.Open();
                    DbTransaction tran = conn.BeginTransaction();
                    try
                    {
                        List<string> orderLineIDList = new List<string>();
                        for (i = 0; i < pickDetailInfo.Count; i++)
                        {
                            if (pickDetailInfo[i].Status == OrderStatus.Shipped)
                            {
                                invTransDA.UpdateTransCreatedDateByDocID(dataBase, tran, pickDetailInfo[i].PickDetailID, TransType.Shipment, TransSourceType.PickingUpdate, this.pubParasInfo.UserID, actualShipDate, whLoginID);
                                pickDetailDa.UpdatePickDetailUpdateDateByPickDetailID(dataBase, tran, pickDetailInfo[i].PickDetailID, actualShipDate, this.pubParasInfo.UserID, whLoginID);
                                if (!orderLineIDList.Contains(pickDetailInfo[i].OrderLineID.ToString()))
                                {
                                    orderLineIDList.Add(pickDetailInfo[i].OrderLineID.ToString());
                                }
                            }
                        }
                        if ((orderLineIDList != null) && (orderLineIDList.Count > 0))
                        {
                            for (i = 0; i < orderLineIDList.Count; i++)
                            {
                                orderDetailDA.UpdateOrderDetailActualShipDateByOrderID(dataBase, tran, orderID, orderLineIDList[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                                result = result + orderLineIDList[i] + ",";
                            }
                        }
                        ordersDA.UpdateOrderActualShipDateByOrderID(dataBase, tran, orderID, actualShipDate, this.pubParasInfo.UserID, whLoginID);
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return (string.IsNullOrEmpty(result) ? "" : result.Substring(0, result.Length - 1));
        }

        public string UpateActualShipDateByPickDetailID(List<string> pickDetailID, List<string> OrderID, List<string> LineID, string actualShipDate)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                int i;
                for (i = 0; pickDetailID.Count > i; i++)
                {
                    invTransDA.UpdateTransCreatedDateByDocID(dataBase, tran, pickDetailID[i], TransType.Shipment, TransSourceType.PickingUpdate, this.pubParasInfo.UserID, actualShipDate, whLoginID);
                    pickDetailDa.UpdatePickDetailUpdateDateByPickDetailID(dataBase, tran, pickDetailID[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                    temp = temp + pickDetailID[i] + ",";
                }
                for (i = 0; OrderID.Count > i; i++)
                {
                    List<PickDetailInfo> pickDetailInfo = pickDetailDa.GetPickDetailByOrderID(dataBase, tran, OrderID[i], LineID[i], whLoginID, this.pubParasInfo);
                    if ((pickDetailInfo != null) && (pickDetailInfo.Count > 0))
                    {
                        if (pickDetailInfo.Count > 1)
                        {
                            OrderDetailInfo orderdetailInfo = orderDetailDA.GetOrderDetailByID(dataBase, tran, OrderID[i], LineID[i], whLoginID, this.pubParasInfo);
                            if ((orderdetailInfo != null) && (orderdetailInfo.ActualShipDate < DateTime.Parse(actualShipDate)))
                            {
                                orderDetailDA.UpdateOrderDetailActualShipDateByOrderID(dataBase, tran, OrderID[i], LineID[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                            }
                        }
                        else
                        {
                            orderDetailDA.UpdateOrderDetailActualShipDateByOrderID(dataBase, tran, OrderID[i], LineID[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                        }
                    }
                    OrdersInfo orderInfo = ordersDA.GetOrdersByID(dataBase, tran, OrderID[i], whLoginID, this.pubParasInfo);
                    if (orderInfo != null)
                    {
                        if (orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, OrderID[i], whLoginID, this.pubParasInfo).Count > 1)
                        {
                            if (orderInfo.ActualShipDate < DateTime.Parse(actualShipDate))
                            {
                                ordersDA.UpdateOrderActualShipDateByOrderID(dataBase, tran, OrderID[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                            }
                        }
                        else
                        {
                            ordersDA.UpdateOrderActualShipDateByOrderID(dataBase, tran, OrderID[i], actualShipDate, this.pubParasInfo.UserID, whLoginID);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        private void UpdateIntransitStatus(List<string> intransitIDs, IntransitBLL intransitBll, string updateBy, string whLoginID)
        {
            if ((intransitIDs != null) && (intransitIDs.Count > 0))
            {
                DataBase dataBase2 = new DataBase();
                DbConnection conn2 = dataBase2.connection;
                conn2.Open();
                DbTransaction tran2 = conn2.BeginTransaction();
                try
                {
                    for (int i = 0; i < intransitIDs.Count; i++)
                    {
                        IntransitInfo intransitInfo = intransitBll.GetIntransitInfoByID(dataBase2, tran2, intransitIDs[i], this.CurrentWH);
                        string status = intransitBll.GetIntransitInfoStatus(intransitInfo);
                        inTransitDA.UpdateIntransitStatus(dataBase2, tran2, intransitIDs[i], status, updateBy, whLoginID);
                    }
                    tran2.Commit();
                }
                catch
                {
                    tran2.Rollback();
                }
                finally
                {
                    conn2.Close();
                }
            }
        }

        private OrdersInfo UpdateSalesOrderDetailStatusAndQty(string orderID, string lineID, string status, decimal qty, string whLoginID, PubParasInfo pubParasInfo)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderID, whLoginID, pubParasInfo);
            this.UpdateSalesOrderDetailStatusAndQty(ordersInfo, lineID, status, qty, whLoginID, pubParasInfo);
            return ordersInfo;
        }

        private OrdersInfo UpdateSalesOrderDetailStatusAndQty(OrdersInfo ordersInfo, string lineID, string status, decimal qty, string whLoginID, PubParasInfo pubParasInfo)
        {
            if (ordersInfo.Type.ToUpper() == "ONLINE")
            {
                if (string.IsNullOrEmpty(ordersInfo.ReferenceNum))
                {
                    return ordersInfo;
                }
                if (!salesOrderDA.CheckSalesOrderIDUnique(ordersInfo.ReferenceNum, whLoginID))
                {
                    return ordersInfo;
                }
                if (status.ToUpper() == "NEW")
                {
                    status = OrderStatus.Scheduled;
                }
                salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(ordersInfo.ReferenceNum, lineID, status, qty, pubParasInfo.UserID, whLoginID);
            }
            return ordersInfo;
        }

        private OrdersInfo UpdateSalesOrderDetailStatusAndQty(DataBase database, DbTransaction tran, string orderID, string lineID, string status, decimal qty, string whLoginID, PubParasInfo pubParasInfo)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(database, tran, orderID, whLoginID, pubParasInfo);
            this.UpdateSalesOrderDetailStatusAndQty(database, tran, ordersInfo, lineID, status, qty, whLoginID, pubParasInfo);
            return ordersInfo;
        }

        private OrdersInfo UpdateSalesOrderDetailStatusAndQty(DataBase database, DbTransaction tran, OrdersInfo ordersInfo, string lineID, string status, decimal qty, string whLoginID, PubParasInfo pubParasInfo)
        {
            if (ordersInfo.Type.ToUpper() == "ONLINE")
            {
                if (string.IsNullOrEmpty(ordersInfo.ReferenceNum))
                {
                    return ordersInfo;
                }
                if (!salesOrderDA.CheckSalesOrderIDUnique(database, tran, ordersInfo.ReferenceNum, whLoginID))
                {
                    return ordersInfo;
                }
                if (status.ToUpper() == "NEW")
                {
                    status = OrderStatus.Scheduled;
                }
                salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(database, tran, ordersInfo.ReferenceNum, lineID, status, qty, pubParasInfo.UserID, whLoginID);
            }
            return ordersInfo;
        }

        private OrdersInfo UpdateSalesOrderDetailStatusAndQty(DataBase database, DbTransaction tran, OrdersInfo ordersInfo, string lineID, string status, decimal shippedqty, decimal isSubSkuQty, string whLoginID, PubParasInfo pubParasInfo)
        {
            if (ordersInfo.Type.ToUpper() == "ONLINE")
            {
                if (string.IsNullOrEmpty(ordersInfo.ReferenceNum))
                {
                    return ordersInfo;
                }
                if (!salesOrderDA.CheckSalesOrderIDUnique(database, tran, ordersInfo.ReferenceNum, whLoginID))
                {
                    return ordersInfo;
                }
                if (status.ToUpper() == "NEW")
                {
                    status = OrderStatus.Scheduled;
                }
                salesOrderDetailDA.UpdateSalesOrderDetailStatusAndQty(database, tran, ordersInfo.ReferenceNum, lineID, status, shippedqty, isSubSkuQty, pubParasInfo.UserID, whLoginID);
            }
            return ordersInfo;
        }

        private string UpdateSalesOrderStatus(List<OrdersInfo> ordersInfo)
        {
            string status = OrderStatus.Scheduled;
            if ((ordersInfo != null) && (ordersInfo.Count > 0))
            {
                int totalCount = ordersInfo.Count;
                int New = 0;
                int PartPreAllocated = 0;
                int PreAllocated = 0;
                int PartAllocated = 0;
                int Allocated = 0;
                int PartPicked = 0;
                int Picked = 0;
                int PartShipped = 0;
                int Shipped = 0;
                for (int i = 0; i < ordersInfo.Count; i++)
                {
                    string tmpStatus = ordersInfo[i].Status.ToUpper();
                    if (tmpStatus == OrderStatus.New.ToUpper())
                    {
                        New++;
                    }
                    if (tmpStatus == OrderStatus.PartPreAllocated.ToUpper())
                    {
                        PartPreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PreAllocated.ToUpper())
                    {
                        PreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PartAllocated.ToUpper())
                    {
                        PartAllocated++;
                    }
                    if (tmpStatus == OrderStatus.Allocated.ToUpper())
                    {
                        Allocated++;
                    }
                    if (tmpStatus == OrderStatus.PartPicked.ToUpper())
                    {
                        PartPicked++;
                    }
                    if (tmpStatus == OrderStatus.Picked.ToUpper())
                    {
                        Picked++;
                    }
                    if (tmpStatus == OrderStatus.PartShipped.ToUpper())
                    {
                        PartShipped++;
                    }
                    if (tmpStatus == OrderStatus.Shipped.ToUpper())
                    {
                        Shipped++;
                    }
                }
                if (New == 0)
                {
                    status = OrderStatus.Scheduled;
                }
                if (PartPreAllocated > 0)
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if ((PreAllocated > 0) && (PreAllocated < totalCount))
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if (PreAllocated == totalCount)
                {
                    status = OrderStatus.PreAllocated;
                }
                if (PartAllocated > 0)
                {
                    status = OrderStatus.PartAllocated;
                }
                if ((Allocated > 0) && (Allocated < totalCount))
                {
                    status = OrderStatus.PartAllocated;
                }
                if (Allocated == totalCount)
                {
                    status = OrderStatus.Allocated;
                }
                if (PartPicked > 0)
                {
                    status = OrderStatus.PartPicked;
                }
                if ((Picked > 0) && (Picked < totalCount))
                {
                    status = OrderStatus.PartPicked;
                }
                if (Picked == totalCount)
                {
                    status = OrderStatus.Picked;
                }
                if (PartShipped > 0)
                {
                    status = OrderStatus.PartShipped;
                }
                if ((Shipped > 0) && (Shipped < totalCount))
                {
                    status = OrderStatus.PartShipped;
                }
                if (Shipped == totalCount)
                {
                    status = OrderStatus.Shipped;
                }
            }
            return status;
        }

        private OrdersInfo UpdateSalesOrderStatus(string orderID, string whLoginID, PubParasInfo pubParasInfo)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderID, whLoginID, pubParasInfo);
            if (ordersInfo.Type.ToUpper() == "ONLINE")
            {
                if (string.IsNullOrEmpty(ordersInfo.ReferenceNum))
                {
                    return ordersInfo;
                }
                if (!salesOrderDA.CheckSalesOrderIDUnique(ordersInfo.ReferenceNum, whLoginID))
                {
                    return ordersInfo;
                }
                List<OrdersInfo> orderList = ordersDA.GetOrderListByReferenceNumAndType(ordersInfo.ReferenceNum, "ONLINE", whLoginID, pubParasInfo);
                string strStatus = this.UpdateSalesOrderStatus(orderList);
                if (!string.IsNullOrEmpty(strStatus))
                {
                    salesOrderDA.UpdateSalesOrderStatus(ordersInfo.ReferenceNum, strStatus, pubParasInfo.UserID, whLoginID);
                }
            }
            return ordersInfo;
        }

        private OrdersInfo UpdateSalesOrderStatus(DataBase database, DbTransaction tran, string orderID, string whLoginID, PubParasInfo pubParasInfo)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(database, tran, orderID, whLoginID, pubParasInfo);
            if (ordersInfo.Type.ToUpper() == "ONLINE")
            {
                if (string.IsNullOrEmpty(ordersInfo.ReferenceNum))
                {
                    return ordersInfo;
                }
                if (!salesOrderDA.CheckSalesOrderIDUnique(database, tran, ordersInfo.ReferenceNum, whLoginID))
                {
                    return ordersInfo;
                }
                List<OrdersInfo> orderList = ordersDA.GetOrderListByReferenceNumAndType(database, tran, ordersInfo.ReferenceNum, "ONLINE", whLoginID, pubParasInfo);
                string strStatus = this.UpdateSalesOrderStatus(orderList);
                if (!string.IsNullOrEmpty(strStatus))
                {
                    salesOrderDA.UpdateSalesOrderStatus(database, tran, ordersInfo.ReferenceNum, strStatus, pubParasInfo.UserID, whLoginID);
                }
            }
            return ordersInfo;
        }

        public string UpdateShippUDFByOrderID(List<OrderDetailInfo> orderDetailInfo)
        {
            string strTemp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                foreach (OrderDetailInfo info in orderDetailInfo)
                {
                    orderDetailDA.UpdateOrderDetailUDF(dataBase, tran, info, this.dataBaseID[0], this.pubParasInfo);
                    strTemp = strTemp + info.LineID + ",";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                tran.Rollback();
            }
            finally
            {
                conn.Close();
            }
            return strTemp;
        }

        public string waveOrderActions(string waveID, List<string> orderID, List<string> orderLineID, string waveOrderType, string updatedBy)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            for (int i = 0; orderID.Count > i; i++)
            {
                List<string> gInitLocal12;
                List<string> gInitLocal13;
                List<string> pickDetailID = new List<string>();
                string CS40001 = waveOrderType.ToUpper();
                if (CS40001 != null)
                {
                    if (!(CS40001 == "PREALLOCATION"))
                    {
                        if (CS40001 == "ALLOCATION")
                        {
                            goto Label_00B3;
                        }
                        if (CS40001 == "REVERTPREALLOCATION")
                        {
                            goto Label_00E0;
                        }
                        if (CS40001 == "REVERTALLOCATION")
                        {
                            goto Label_010D;
                        }
                        if (CS40001 == "RELEASETASKS")
                        {
                            goto Label_0171;
                        }
                    }
                    else
                    {
                        List<string> gInitLocal11 = new List<string> {
                            orderLineID[i]
                        };
                        temp = this.BatchPreAllocate(orderID[i], gInitLocal11, updatedBy);
                    }
                }
                continue;
            Label_00B3:
                gInitLocal12 = new List<string>();
                gInitLocal12.Add(orderLineID[i]);
                temp = this.BatchAllocate(orderID[i], gInitLocal12, updatedBy);
                continue;
            Label_00E0:
                gInitLocal13 = new List<string>();
                gInitLocal13.Add(orderLineID[i]);
                temp = this.RevertPreAllocate(orderID[i], gInitLocal13, updatedBy);
                continue;
            Label_010D:
                pickDetailID = pickDetailDa.GetPickDetailIDByOrderLineID(orderID[i], orderLineID[i], PickDetailStatus.New, whLoginID);
                if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.RevertAllocate(pickDetailID, updatedBy)))
                {
                    temp = temp + orderID[i] + ",";
                }
                continue;
            Label_0171:
                pickDetailID = pickDetailDa.GetPickDetailIDByOrderLineID(orderID[i], orderLineID[i], PickDetailStatus.New, whLoginID);
                if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.ReleasePickTasks(pickDetailID, updatedBy)))
                {
                    temp = temp + orderID[i] + ",";
                }
            }
            new WaveBLL(this.pubParasInfo).UpdateWaveStatusByWaveID(waveID);
            return temp;
        }

        public string WaveReleasePickTasks(List<string> waveID, string userID)
        {
            string whLoginID = this.dataBaseID[0];
            string temp = string.Empty;
            for (int n = 0; waveID.Count > n; n++)
            {
                List<WaveDetailInfo> waveDetailInfos = waveDetailDA.GetWaveDetailListByID(waveID[n], whLoginID);
                if ((waveDetailInfos != null) && (waveDetailInfos.Count > 0))
                {
                    for (int i = 0; i < waveDetailInfos.Count; i++)
                    {
                        List<string> pickDetailID = pickDetailDa.GetPickDetailIDByOrderID(waveDetailInfos[i].OrderID, PickDetailStatus.New, whLoginID);
                        if (((pickDetailID != null) && (pickDetailID.Count > 0)) && !string.IsNullOrEmpty(this.ReleasePickTasks(pickDetailID, userID, this.pubParasInfo.UserID)))
                        {
                            temp = temp + waveDetailInfos[i].OrderID + ",";
                        }
                    }
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }
    }
}

